In this sample project, we will learn major features of App Runner.
Learn the features below using the CDK code:
- App Runner Service
- Container deployment with ECR image
- Container deployment with change from CodeCommit repository
- Deploy VPC stack
- Deploy IAM Role stack
- Docker build, deploy ECR and CodeCommit repository stack
- Deploy App Runner stack
- Deploy with ECR image
- Deploy with CodeCommit repository
npm install -g aws-cdk@2.32.1
npm install -g cdk-ecr-deployment@2.5.5
# install packages in the root folder
npm install
cdk bootstrapUse the cdk command-line toolkit to interact with your project:
cdk deploy: deploys your app into an AWS accountcdk synth: synthesizes an AWS CloudFormation template for your appcdk diff: compares your app with the deployed stackcdk watch: deployment every time a file change is detected
| Stack | Time To Complete | |
|---|---|---|
| 1 | VPC | 3m 30s (optional) |
| 2 | IAM roles | 1m |
| 3 | ECR and CodeCommit repository including Docker build | 4m |
| 4 | App Runner | 6m |
| Total | 11m (14m 30s with a new VPC) |
Use the deploy-all.sh file if you want to deploy all stacks without prompt at a time.
Deploy a new VPC:
cd vpc
cdk deployThe VPC ID will be saved into the SSM Parameter Store(/apprunner-cdk/vpc-id) to refer from other stacks.
To use the existing VPC, use the -c vpcId context parameter or create SSM Parameter:
aws ssm put-parameter --name "/apprunner-cdk/vpc-id" --value "{existing-vpc-id}" --type String Create the App Ruller access Execution role for ECR.
cd ../02-iam-role
cdk deploy 02-iam-role/lib/02-iam-role-stack.ts
cd ../03-ecr-codecommit
cdk deploy --outputs-file ./cdk-outputs.json
cat ./cdk-outputs.json 03-ecr-codecommit/lib/ecr-codecommit-stack.ts
Crearte a App Runne Service.
cd ../04-apprunner
cdk deploy ecs-restapi-service refers the SSM parameters below:
- /apprunner-cdk/vpc-id
- /apprunner-cdk/access-arn
04-apprunner/lib/apprunner-stack.ts
IMPORTANT
If the ECS cluster was re-created, you HAVE to deploy after cdk.context.json files deletion with the below:
find . -name "cdk.context.json" -exec rm -f {} \;