docs
Initial Deployment
CDK
CDK Deploy

Deploying Your Application with CDK 🚀

Now that you've bootstrapped your AWS environments, it's time to deploy your application using AWS CDK.

Overview

The cdk deploy command compiles your CDK app and deploys it to your AWS account. It synthesizes CloudFormation templates and handles the deployment process, creating or updating the necessary AWS resources.

Deployment Commands

Depending on the environment you wish to deploy to (Staging or Production), use the following commands:

cdk deploy --qualifier [qualifier name] --require-approval never --profile [profile name]
  • --require-approval never: This flag bypasses any prompts for manual approval, allowing the deployment to proceed without interruption.

⚠️ The [qualifier name] MUST match the const appName value in the cdk/bin/cdk.ts file.

** must be an alphanumeric identifier of at most 10 characters **

Let's Deploy!

Let's run cdk deploy for staging first.

For Staging Environment

cdk deploy --qualifier launchgoat --require-approval never --profile awslaunchgoat-staging

It will first undergo the synthesis process. Synthesis is the step in the CDK lifecycle where constructs (written in a programming language) are translated into CloudFormation templates (JSON/YAML).

Create Permission Set

Next, it will load the build definition from our Dockerfile, then upload the Docker image to AWS ECR.

Create Permission Set

Once done, it will create CloudFormation changeset.

Create Permission Set

Note that initial deployment takes time and can last up to 15-20 minutes.

Once done, you will see:

 ✅  CdkStack
 ✨  Deployment time: 1104.64s

⚠️ If you run into this error:

This CDK deployment requires bootstrap stack version '6', but during the confirmation via SSM parameter

Then refer to this.

⚠️ If you encounter any errors, or if the process does not complete after 30 minutes or more.

Then destroy the resources and start again from bootstrapping.


Congrats! Successfully deployed. Let's deploy to the production environment. Before we run the command, we need to do 2 things--remember?.

  1. update .env
  • Go back to the .env file in the cdk folder. Comment out the Staging section and uncomment the Production section.
  1. run sso login for production
aws sso login --profile awslaunchgoat-prod

For Production Environment

cdk deploy --qualifier launchgoat --require-approval never --profile awslaunchgoat-prod

Great work! You've come a long way, and it's definitely not been easy.