Build Environment

Install prerequisites

sudo yum install -y jq
npm i -g -f aws-cdk@1.54.0
git clone https://github.com/adamjkeller/ecs-codepipeline-demo ~/environment/ecs-codepipeline-demo
cd ~/environment/ecs-codepipeline-demo

Build the stack

npm install
npm run build

Bootstrap CDK

This creates an S3 bucket that holds the file assets and the resulting CloudFormation template to deploy.

cdk bootstrap

Code Review

Similar to the previous environments, we follow the same format to build the environment using AWS CDK.

Let's Dive in

Synthesize the CloudFormation templates

cdk synth

Review what the cdk is proposing to build and/or change in the environment

cdk diff

Deploy the resources

  • Note:

    • The stack will create a new VPC with CIDR 10.0.0.0/16
    • The stack will create a new CodeCommit repository named demo-app

      cdk deploy --require-approval never
      
  • A successful deployment will output the below values

    • BlueGreenUsingEcsStack.ecsBlueGreenLBDns
    • BlueGreenUsingEcsStack.ecsBlueGreenCodeRepo

Exporting the Load Balancer URL

export cloudformation_outputs=$(aws cloudformation describe-stacks --stack-name BlueGreenUsingEcsStack | jq .Stacks[].Outputs)
export load_balancer_url=$(echo $cloudformation_outputs | jq -r '.[]| select(.ExportName | contains("ecsBlueGreenLBDns"))| .OutputValue')
  • Let’s see the deployed version of the application