1.204.0 • Published 11 months ago

@aws-cdk/aws-apprunner v1.204.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

AWS::AppRunner Construct Library


End-of-Support

AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2.

For more information on how to migrate, see the Migrating to AWS CDK v2 guide.

doc: https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html


This module is part of the AWS Cloud Development Kit project.

import * as apprunner from '@aws-cdk/aws-apprunner';

Introduction

AWS App Runner is a fully managed service that makes it easy for developers to quickly deploy containerized web applications and APIs, at scale and with no prior infrastructure experience required. Start with your source code or a container image. App Runner automatically builds and deploys the web application and load balances traffic with encryption. App Runner also scales up or down automatically to meet your traffic needs. With App Runner, rather than thinking about servers or scaling, you have more time to focus on your applications.

Service

The Service construct allows you to create AWS App Runner services with ECR Public, ECR or Github with the source property in the following scenarios:

  • Source.fromEcr() - To define the source repository from ECR.
  • Source.fromEcrPublic() - To define the source repository from ECR Public.
  • Source.fromGitHub() - To define the source repository from the Github repository.
  • Source.fromAsset() - To define the source from local asset directory.

ECR Public

To create a Service with ECR Public:

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: { port: 8000 },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  }),
});

ECR

To create a Service from an existing ECR repository:

import * as ecr from '@aws-cdk/aws-ecr';

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcr({
    imageConfiguration: { port: 80 },
    repository: ecr.Repository.fromRepositoryName(this, 'NginxRepository', 'nginx'),
    tagOrDigest: 'latest',
  }),
});

To create a Service from local docker image asset directory built and pushed to Amazon ECR:

import * as assets from '@aws-cdk/aws-ecr-assets';

const imageAsset = new assets.DockerImageAsset(this, 'ImageAssets', {
  directory: path.join(__dirname, './docker.assets'),
});
new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromAsset({
    imageConfiguration: { port: 8000 },
    asset: imageAsset,
  }),
});

GitHub

To create a Service from the GitHub repository, you need to specify an existing App Runner Connection.

See Managing App Runner connections for more details.

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromGitHub({
    repositoryUrl: 'https://github.com/aws-containers/hello-app-runner',
    branch: 'main',
    configurationSource: apprunner.ConfigurationSourceType.REPOSITORY,
    connection: apprunner.GitHubConnection.fromConnectionArn('CONNECTION_ARN'),
  }),
});

Use codeConfigurationValues to override configuration values with the API configuration source type.

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromGitHub({
    repositoryUrl: 'https://github.com/aws-containers/hello-app-runner',
    branch: 'main',
    configurationSource: apprunner.ConfigurationSourceType.API,
    codeConfigurationValues: {
      runtime: apprunner.Runtime.PYTHON_3,
      port: '8000',
      startCommand: 'python app.py',
      buildCommand: 'yum install -y pycairo && pip install -r requirements.txt',
    },
    connection: apprunner.GitHubConnection.fromConnectionArn('CONNECTION_ARN'),
  }),
});

IAM Roles

You are allowed to define instanceRole and accessRole for the Service.

instanceRole - The IAM role that provides permissions to your App Runner service. These are permissions that your code needs when it calls any AWS APIs.

accessRole - The IAM role that grants the App Runner service access to a source repository. It's required for ECR image repositories (but not for ECR Public repositories). If not defined, a new access role will be generated when required.

See App Runner IAM Roles for more details.

VPC Connector

To associate an App Runner service with a custom VPC, define vpcConnector for the service.

import * as ec2 from '@aws-cdk/aws-ec2';

const vpc = new ec2.Vpc(this, 'Vpc', {
  cidr: '10.0.0.0/16',
});

const vpcConnector = new apprunner.VpcConnector(this, 'VpcConnector', {
  vpc,
  vpcSubnets: vpc.selectSubnets({ subnetType: ec2.SubnetType.PUBLIC }),
  vpcConnectorName: 'MyVpcConnector',
});

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: { port: 8000 },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  }),
  vpcConnector,
});
1.204.0

11 months ago

1.203.0

11 months ago

1.201.0

12 months ago

1.199.0

1 year ago

1.200.0

1 year ago

1.202.0

12 months ago

1.195.0

1 year ago

1.194.0

1 year ago

1.198.1

1 year ago

1.198.0

1 year ago

1.193.0

1 year ago

1.197.0

1 year ago

1.192.0

1 year ago

1.196.0

1 year ago

1.187.0

1 year ago

1.191.0

1 year ago

1.186.0

1 year ago

1.186.1

1 year ago

1.190.0

1 year ago

1.185.0

1 year ago

1.189.0

1 year ago

1.188.0

1 year ago

1.181.0

1 year ago

1.183.0

1 year ago

1.181.1

1 year ago

1.178.0

2 years ago

1.180.0

1 year ago

1.184.0

1 year ago

1.184.1

1 year ago

1.182.0

1 year ago

1.177.0

2 years ago

1.179.0

2 years ago

1.176.0

2 years ago

1.175.0

2 years ago

1.170.0

2 years ago

1.174.0

2 years ago

1.172.0

2 years ago

1.170.1

2 years ago

1.169.0

2 years ago

1.173.0

2 years ago

1.171.0

2 years ago

1.162.0

2 years ago

1.160.0

2 years ago

1.166.1

2 years ago

1.164.0

2 years ago

1.168.0

2 years ago

1.159.0

2 years ago

1.163.0

2 years ago

1.161.0

2 years ago

1.167.0

2 years ago

1.165.0

2 years ago

1.163.2

2 years ago

1.163.1

2 years ago

1.158.0

2 years ago

1.155.0

2 years ago

1.157.0

2 years ago

1.154.0

2 years ago

1.156.0

2 years ago

1.156.1

2 years ago

1.149.0

2 years ago

1.153.0

2 years ago

1.153.1

2 years ago

1.151.0

2 years ago

1.148.0

2 years ago

1.150.0

2 years ago

1.152.0

2 years ago

1.146.0

2 years ago

1.147.0

2 years ago

1.142.0

2 years ago

1.143.0

2 years ago

1.144.0

2 years ago

1.145.0

2 years ago

1.140.0

2 years ago

1.141.0

2 years ago

1.138.2

2 years ago

1.139.0

2 years ago

1.138.1

2 years ago

1.136.0

2 years ago

1.135.0

2 years ago

1.138.0

2 years ago

1.137.0

2 years ago

1.132.0

2 years ago

1.131.0

2 years ago

1.134.0

2 years ago

1.133.0

2 years ago

1.130.0

3 years ago

1.129.0

3 years ago

1.128.0

3 years ago

1.127.0

3 years ago

1.126.0

3 years ago

1.125.0

3 years ago

1.124.0

3 years ago

1.123.0

3 years ago

1.122.0

3 years ago

1.121.0

3 years ago

1.120.0

3 years ago

1.119.0

3 years ago

1.118.0

3 years ago

1.117.0

3 years ago

1.116.0

3 years ago

1.115.0

3 years ago

1.114.0

3 years ago

1.113.0

3 years ago

1.112.0

3 years ago

1.111.0

3 years ago

1.110.1

3 years ago

1.110.0

3 years ago

1.109.0

3 years ago

1.108.0

3 years ago

1.108.1

3 years ago

1.107.0

3 years ago