Package: aws-cdk.aws-apprunner
AWS::AppRunner Construct Library---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 theMigrating to AWS CDK v2guide.This module is part of theAWS Cloud Development Kitproject.importaws_cdk.aws_apprunnerasapprunnerIntroductionAWS 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.ServiceTheServiceconstruct allows you to create AWS App Runner services withECR Public,ECRorGithubwith thesourceproperty in the following scenarios:Source.fromEcr()- To define the source repository fromECR.Source.fromEcrPublic()- To define the source repository fromECR Public.Source.fromGitHub()- To define the source repository from theGithub repository.Source.fromAsset()- To define the source from local asset directory.ECR PublicTo create aServicewith ECR Public:apprunner.Service(self,"Service",source=apprunner.Source.from_ecr_public(image_configuration=apprunner.ImageConfiguration(port=8000),image_identifier="public.ecr.aws/aws-containers/hello-app-runner:latest"))ECRTo create aServicefrom an existing ECR repository:importaws_cdk.aws_ecrasecrapprunner.Service(self,"Service",source=apprunner.Source.from_ecr(image_configuration=apprunner.ImageConfiguration(port=80),repository=ecr.Repository.from_repository_name(self,"NginxRepository","nginx"),tag_or_digest="latest"))To create aServicefrom local docker image asset directory  built and pushed to Amazon ECR:importaws_cdk.aws_ecr_assetsasassetsimage_asset=assets.DockerImageAsset(self,"ImageAssets",directory=path.join(__dirname,"./docker.assets"))apprunner.Service(self,"Service",source=apprunner.Source.from_asset(image_configuration=apprunner.ImageConfiguration(port=8000),asset=image_asset))GitHubTo create aServicefrom the GitHub repository, you need to specify an existing App RunnerConnection.SeeManaging App Runner connectionsfor more details.apprunner.Service(self,"Service",source=apprunner.Source.from_git_hub(repository_url="https://github.com/aws-containers/hello-app-runner",branch="main",configuration_source=apprunner.ConfigurationSourceType.REPOSITORY,connection=apprunner.GitHubConnection.from_connection_arn("CONNECTION_ARN")))UsecodeConfigurationValuesto override configuration values with theAPIconfiguration source type.apprunner.Service(self,"Service",source=apprunner.Source.from_git_hub(repository_url="https://github.com/aws-containers/hello-app-runner",branch="main",configuration_source=apprunner.ConfigurationSourceType.API,code_configuration_values=apprunner.CodeConfigurationValues(runtime=apprunner.Runtime.PYTHON_3,port="8000",start_command="python app.py",build_command="yum install -y pycairo && pip install -r requirements.txt"),connection=apprunner.GitHubConnection.from_connection_arn("CONNECTION_ARN")))IAM RolesYou are allowed to defineinstanceRoleandaccessRolefor theService.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.SeeApp Runner IAM Rolesfor more details.VPC ConnectorTo associate an App Runner service with a custom VPC, definevpcConnectorfor the service.importaws_cdk.aws_ec2asec2vpc=ec2.Vpc(self,"Vpc",cidr="10.0.0.0/16")vpc_connector=apprunner.VpcConnector(self,"VpcConnector",vpc=vpc,vpc_subnets=vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC),vpc_connector_name="MyVpcConnector")apprunner.Service(self,"Service",source=apprunner.Source.from_ecr_public(image_configuration=apprunner.ImageConfiguration(port=8000),image_identifier="public.ecr.aws/aws-containers/hello-app-runner:latest"),vpc_connector=vpc_connector)