2.139.1-alpha.0 • Published 2 days ago

@aws-cdk/aws-apprunner-alpha v2.139.1-alpha.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 days ago

AWS::AppRunner Construct Library


cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


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

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

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.

The Service construct implements IGrantable.

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-lib/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:

You can specify whether to enable continuous integration from the source repository with the autoDeploymentsEnabled flag.

import * as assets from 'aws-cdk-lib/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,
  }),
  autoDeploymentsEnabled: true,
});

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. If not defined, a new instance role will be generated when required.

To add IAM policy statements to this role, use addToRolePolicy():

import * as iam from 'aws-cdk-lib/aws-iam';

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

service.addToRolePolicy(new iam.PolicyStatement({
  effect: iam.Effect.ALLOW,
  actions: ['s3:GetObject'],
  resources: ['*'],
}))

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-lib/aws-ec2';

const vpc = new ec2.Vpc(this, 'Vpc', {
  ipAddresses: ec2.IpAddresses.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,
});

Secrets Manager

To include environment variables integrated with AWS Secrets Manager, use the environmentSecrets attribute. You can use the addSecret method from the App Runner Service class to include secrets from outside the service definition.

import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
import * as ssm from 'aws-cdk-lib/aws-ssm';

declare const stack: Stack;

const secret = new secretsmanager.Secret(stack, 'Secret');
const parameter = ssm.StringParameter.fromSecureStringParameterAttributes(stack, 'Parameter', {
  parameterName: '/name',
  version: 1,
});

const service = new apprunner.Service(stack, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: {
      port: 8000,
      environmentSecrets: {
        SECRET: apprunner.Secret.fromSecretsManager(secret),
        PARAMETER: apprunner.Secret.fromSsmParameter(parameter),
        SECRET_ID: apprunner.Secret.fromSecretsManagerVersion(secret, { versionId: 'version-id' }),
        SECRET_STAGE: apprunner.Secret.fromSecretsManagerVersion(secret, { versionStage: 'version-stage' }),
      },
    },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  })
});

service.addSecret('LATER_SECRET', apprunner.Secret.fromSecretsManager(secret, 'field'));

HealthCheck

To configure the health check for the service, use the healthCheck attribute.

You can specify it by static methods HealthCheck.http or HealthCheck.tcp.

new apprunner.Service(this, 'Service', {
  source: apprunner.Source.fromEcrPublic({
    imageConfiguration: { port: 8000 },
    imageIdentifier: 'public.ecr.aws/aws-containers/hello-app-runner:latest',
  }),
  healthCheck: apprunner.HealthCheck.http({
    healthyThreshold: 5,
    interval: Duration.seconds(10),
    path: '/',
    timeout: Duration.seconds(10),
    unhealthyThreshold: 10,
  }),
});
2.139.1-alpha.0

2 days ago

2.139.0-alpha.0

7 days ago

2.138.0-alpha.0

13 days ago

2.137.0-alpha.0

21 days ago

2.136.1-alpha.0

22 days ago

2.136.0-alpha.0

26 days ago

2.135.0-alpha.0

30 days ago

2.134.0-alpha.0

1 month ago

2.133.0-alpha.0

2 months ago

2.132.1-alpha.0

2 months ago

2.132.0-alpha.0

2 months ago

2.131.0-alpha.0

2 months ago

2.129.0-alpha.0

2 months ago

2.130.0-alpha.0

2 months ago

2.128.0-alpha.0

3 months ago

2.127.0-alpha.0

3 months ago

2.126.0-alpha.0

3 months ago

2.125.0-alpha.0

3 months ago

2.124.0-alpha.0

3 months ago

2.123.0-alpha.0

3 months ago

2.122.0-alpha.0

3 months ago

2.121.0-alpha.0

4 months ago

2.120.0-alpha.0

4 months ago

2.121.1-alpha.0

4 months ago

2.119.0-alpha.0

4 months ago

2.118.0-alpha.0

4 months ago

2.117.0-alpha.0

4 months ago

2.116.1-alpha.0

4 months ago

2.116.0-alpha.0

4 months ago

2.115.0-alpha.0

5 months ago

2.114.1-alpha.0

5 months ago

2.114.0-alpha.0

5 months ago

2.113.0-alpha.0

5 months ago

2.111.0-alpha.0

5 months ago

2.112.0-alpha.0

5 months ago

2.109.0-alpha.0

6 months ago

2.106.0-alpha.0

6 months ago

2.110.0-alpha.0

6 months ago

2.105.0-alpha.0

6 months ago

2.110.1-alpha.0

5 months ago

2.108.1-alpha.0

6 months ago

2.107.0-alpha.0

6 months ago

2.108.0-alpha.0

6 months ago

2.106.1-alpha.0

6 months ago

2.103.0-alpha.0

6 months ago

2.103.1-alpha.0

6 months ago

2.102.1-alpha.0

6 months ago

2.104.0-alpha.0

6 months ago

2.100.0-alpha.0

7 months ago

2.88.0-alpha.0

10 months ago

2.101.1-alpha.0

7 months ago

2.99.1-alpha.0

7 months ago

2.90.0-alpha.0

9 months ago

2.96.1-alpha.0

8 months ago

2.98.0-alpha.0

7 months ago

2.89.0-alpha.0

9 months ago

2.95.0-alpha.0

8 months ago

2.96.0-alpha.0

8 months ago

2.94.0-alpha.0

8 months ago

2.95.1-alpha.0

8 months ago

2.97.0-alpha.0

7 months ago

2.102.0-alpha.0

7 months ago

2.87.0-alpha.0

10 months ago

2.91.0-alpha.0

9 months ago

2.92.0-alpha.0

9 months ago

2.86.0-alpha.0

10 months ago

2.99.0-alpha.0

7 months ago

2.97.1-alpha.0

7 months ago

2.96.2-alpha.0

8 months ago

2.101.0-alpha.0

7 months ago

2.93.0-alpha.0

8 months ago

2.83.0-alpha.0

11 months ago

2.82.0-alpha.0

11 months ago

2.84.0-alpha.0

11 months ago

2.85.0-alpha.0

11 months ago

2.83.1-alpha.0

11 months ago

2.78.0-alpha.0

12 months ago

2.75.0-alpha.0

1 year ago

2.80.0-alpha.0

12 months ago

2.74.0-alpha.0

1 year ago

2.79.1-alpha.0

12 months ago

2.81.0-alpha.0

11 months ago

2.79.0-alpha.0

12 months ago

2.76.0-alpha.0

1 year ago

2.77.0-alpha.0

1 year ago

2.75.1-alpha.0

1 year ago

2.73.0-alpha.0

1 year ago

2.65.0-alpha.0

1 year ago

2.63.1-alpha.0

1 year ago

2.72.0-alpha.0

1 year ago

2.68.0-alpha.0

1 year ago

2.66.1-alpha.0

1 year ago

2.63.2-alpha.0

1 year ago

2.67.0-alpha.0

1 year ago

2.72.1-alpha.0

1 year ago

2.66.0-alpha.0

1 year ago

2.71.0-alpha.0

1 year ago

2.64.0-alpha.0

1 year ago

2.69.0-alpha.0

1 year ago

2.70.0-alpha.0

1 year ago

2.62.0-alpha.0

1 year ago

2.58.1-alpha.0

1 year ago

2.60.0-alpha.0

1 year ago

2.57.0-alpha.0

1 year ago

2.58.0-alpha.0

1 year ago

2.62.2-alpha.0

1 year ago

2.59.0-alpha.0

1 year ago

2.61.0-alpha.0

1 year ago

2.62.1-alpha.0

1 year ago

2.63.0-alpha.0

1 year ago

2.61.1-alpha.0

1 year ago

2.46.0-alpha.0

2 years ago

2.52.0-alpha.0

1 year ago

2.53.0-alpha.0

1 year ago

2.56.0-alpha.0

1 year ago

2.49.0-alpha.0

2 years ago

2.51.1-alpha.0

1 year ago

2.52.1-alpha.0

1 year ago

2.49.1-alpha.0

2 years ago

2.55.1-alpha.0

1 year ago

2.48.0-alpha.0

2 years ago

2.50.0-alpha.0

1 year ago

2.54.0-alpha.0

1 year ago

2.56.1-alpha.0

1 year ago

2.55.0-alpha.0

1 year ago

2.47.0-alpha.0

2 years ago

2.51.0-alpha.0

1 year ago

2.45.0-alpha.0

2 years ago

2.44.0-alpha.0

2 years ago

2.38.1-alpha.0

2 years ago

2.39.1-alpha.0

2 years ago

2.43.1-alpha.0

2 years ago

2.42.0-alpha.0

2 years ago

2.41.0-alpha.0

2 years ago

2.42.1-alpha.0

2 years ago

2.38.0-alpha.0

2 years ago

2.40.0-alpha.0

2 years ago

2.39.0-alpha.0

2 years ago

2.43.0-alpha.0

2 years ago

2.33.0-alpha.0

2 years ago

2.31.1-alpha.0

2 years ago

2.27.0-alpha.0

2 years ago

2.29.1-alpha.0

2 years ago

2.32.1-alpha.0

2 years ago

2.26.0-alpha.0

2 years ago

2.37.0-alpha.0

2 years ago

2.30.0-alpha.0

2 years ago

2.34.2-alpha.0

2 years ago

2.34.0-alpha.0

2 years ago

2.28.1-alpha.0

2 years ago

2.31.2-alpha.0

2 years ago

2.35.0-alpha.0

2 years ago

2.31.0-alpha.0

2 years ago

2.29.0-alpha.0

2 years ago

2.32.0-alpha.0

2 years ago

2.37.1-alpha.0

2 years ago

2.34.1-alpha.0

2 years ago

2.36.0-alpha.0

2 years ago

2.28.0-alpha.0

2 years ago

2.25.0-alpha.0

2 years ago

2.22.0-alpha.0

2 years ago

2.24.1-alpha.0

2 years ago

2.24.0-alpha.0

2 years ago

2.23.0-alpha.0

2 years ago

2.19.0-alpha.0

2 years ago

2.16.0-alpha.0

2 years ago

2.20.0-alpha.0

2 years ago

2.18.0-alpha.0

2 years ago

2.21.1-alpha.0

2 years ago

2.17.0-alpha.0

2 years ago

2.21.0-alpha.0

2 years ago

2.14.0-alpha.0

2 years ago

2.15.0-alpha.0

2 years ago

2.9.0-alpha.0

2 years ago

2.4.0-alpha.0

2 years ago

2.12.0-alpha.0

2 years ago

2.7.0-alpha.0

2 years ago

2.6.0-alpha.0

2 years ago

2.2.0-alpha.0

2 years ago

2.3.0-alpha.0

2 years ago

2.8.0-alpha.0

2 years ago

2.13.0-alpha.0

2 years ago

2.5.0-alpha.0

2 years ago

2.11.0-alpha.0

2 years ago

2.10.0-alpha.0

2 years ago

2.1.0-alpha.0

2 years ago

2.0.0-alpha.7

2 years ago

2.0.0-alpha.8

2 years ago

2.0.0-alpha.9

2 years ago

2.0.0-alpha.11

2 years ago

2.0.0-alpha.10

2 years ago

2.0.0-alpha.5

2 years ago

2.0.0-alpha.6

2 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.1

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-rc.24

3 years ago

2.0.0-rc.23

3 years ago