The CDK Construct Library for AWS::AppRunner
Project description
AWS::AppRunner Construct Library
---All classes with the
Cfn
prefix in this module (CFN Resources) are always stable and safe to use.
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 aws_cdk.aws_apprunner as 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 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 Public
To create a Service
with 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"
)
)
ECR
To create a Service
from an existing ECR repository:
import aws_cdk.aws_ecr as ecr
apprunner.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 a Service
from local docker image asset directory built and pushed to Amazon ECR:
import aws_cdk.aws_ecr_assets as assets
image_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
)
)
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.
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")
)
)
Use codeConfigurationValues
to override configuration values with the API
configuration 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 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 aws_cdk.aws_ec2 as ec2
vpc = 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
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aws-cdk.aws-apprunner-1.169.0.tar.gz
.
File metadata
- Download URL: aws-cdk.aws-apprunner-1.169.0.tar.gz
- Upload date:
- Size: 168.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6c70fecdc283c4ec39a7cae5c3876bc2b8ba11ff238348158d05d74e122fef3 |
|
MD5 | f8993b637f11dd3c0a861bb02a658415 |
|
BLAKE2b-256 | 27dcce085fc469d7fbaab63593a91ec0107558efd2b5feff1a7dad6fdf88e772 |
File details
Details for the file aws_cdk.aws_apprunner-1.169.0-py3-none-any.whl
.
File metadata
- Download URL: aws_cdk.aws_apprunner-1.169.0-py3-none-any.whl
- Upload date:
- Size: 168.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f268ddbc0197277ba44a47b7b3c7f18e5f8c291ce1a47edf2184728315f4cbf2 |
|
MD5 | c1cca916a0c019d344f84ebc91ee391c |
|
BLAKE2b-256 | 7a1557cb14e4e49cf7a106e35a583b53e6d6b3bc94b129098f3814b94cb41fd8 |