Build Environment

Install prerequisites

sudo yum install -y jq
npm i -g -f aws-cdk@1.128.0
nvm install 16.10.0
nvm use 16.10.0
git clone https://github.com/aws-containers/ecs-workshop-blue-green-deployments ~/environment/ecs-workshop-blue-green-deployments
cd ~/environment/ecs-workshop-blue-green-deployments

Build the stack

npm install
npm run build
npm run test

Deploy the container image stack

  • This script bootstraps the CDK in the AWS account
  • Build a CodeCommit repository and a Codebuild project to create container image
./bin/scripts/deploy-container-image-stack.sh

Code review for container image stack

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

Let's Dive in

Let’s push the nginx code sample into CodeCommit repository

  • The source code is available here
  • The buildspec.yml has placeholders for the variables
  • Follow the below steps to upload the code into CodeCommit repository created earlier
export AWS_DEFAULT_REGION=$(aws configure get region)
export CODE_REPO_NAME=nginx-sample
export CODE_REPO_URL=codecommit::$AWS_DEFAULT_REGION://$CODE_REPO_NAME
cd ~/environment && git clone $CODE_REPO_URL && cd $CODE_REPO_NAME
cp ~/environment/ecs-workshop-blue-green-deployments/nginx-sample/* .
git checkout -b main
git remote -v
git add .
git commit -m "First commit"
git push --set-upstream origin main

Deploy the pipeline stack

This script executes below steps

  • Build the container image for code in CodeCommit using CodeBuild
  • Deploy the CodeDeploy and CodePipeline resources for blue/green deployment
  • Deploy the AWS Fargate service using the container image
cd ~/environment/ecs-workshop-blue-green-deployments
./bin/scripts/deploy-pipeline-stack.sh

Code review of pipeline stack

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

Let's Dive in

Exporting the Load Balancer URL

export ALB_DNS=$(aws cloudformation describe-stacks --stack-name BlueGreenPipelineStack --query 'Stacks[*].Outputs[?ExportName==`ecsBlueGreenLBDns`].OutputValue' --output text)
  • Let’s see the deployed version of the application