DevSecOpsSamples / apprunner-cdk

AWS AppRunner with CDK
0 stars 0 forks source link
app-runner aws cdk container no-ops serverless

App Runner sample project with CDK

Build Quality Gate Status Lines of Code

Introduction

In this sample project, we will learn major features of App Runner.

Objectives

Learn the features below using the CDK code:

Table of Contents

  1. Deploy VPC stack
  2. Deploy IAM Role stack
  3. Docker build, deploy ECR and CodeCommit repository stack
  4. Deploy App Runner stack
  5. Deploy with ECR image
  6. Deploy with CodeCommit repository

Prerequisites

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 bootstrap

Use the cdk command-line toolkit to interact with your project:

CDK Stack

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)

Steps

Use the deploy-all.sh file if you want to deploy all stacks without prompt at a time.

Step 1: VPC

Deploy a new VPC:

cd vpc
cdk deploy

01-vpc/lib/vpc-stack.ts

The 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 

Step 3: IAM Role

Create the App Ruller access Execution role for ECR.

cd ../02-iam-role
cdk deploy 

02-iam-role/lib/02-iam-role-stack.ts

Step 3: ECR and CodeCommit repository

cd ../03-ecr-codecommit
cdk deploy --outputs-file ./cdk-outputs.json
cat ./cdk-outputs.json 

03-ecr-codecommit/lib/ecr-codecommit-stack.ts

Step 4: App Runner Service

Crearte a App Runne Service.

cd ../04-apprunner
cdk deploy 

ecs-restapi-service refers the SSM parameters below:

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 {} \;

Clean Up

clean-up.sh

Reference

Docs

CDK Lib

IAM Role & Policy