This project sets up a Windows based ECS Cluster using capacity provider auto-scaling with fully automated Blue/Green deployment powered by AWS Code Deploy. All you
need to pass is your ECR repo name where the image resides in cdk.json via imageRepository
property.
It is assumed that you already have a mechanism in place to build and push your container image to ECR. If you don't have the mechanism in place, Pipeline can easily be extended to introduce a code build stage to build and deploy your container image. As part of demo setup, we have pushed microsoft/iss image from docker hub to ECR as per instructions here.
The cdk.json
file tells the CDK Toolkit how to execute your app.
It is a Maven based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
- Make sure you have AWS CDK installed and configured with an aws account you want to use.
- Ensure you have npm installed.
- Ensure you have java11 installed.
-
Change to lambda directory and install needed dependencies by executing below command.
cd lambda npm install cd ..
Note: This is a one time activity to make sure the lambda function for custom resources has required dependencies.
-
Build the maven project:
mvn clean install
-
Once the project is build successfully, Use CDK commands to diff and deploy the stacks. Application consists of two stacks which needs to be deployed separately.
-
EcsWindowsBlueGreenClusterStack: Sets up Windows based ECS Cluster with auto-scaling. It also sets up a service using CODE_DEPLOY as deployment controller backed by Network load balancer. It also sets up Code deploy application along with a Blue Green deployment group. Finally, It also copies taskdef.json and appspec.yaml files to S3 buckets as zip. This is need to set up Code Pipeline for ECS Blue Green deployment.
cdk synth EcsWindowsBlueGreenClusterStack
cdk deploy EcsWindowsBlueGreenClusterStack --require-approval never
Once the stacks is deployed, you should be able to browse through the service following loadbalancer URL, which will also be available in stack output as
LoadBalancerDnsName
. -
PipelineEcsWindowsBlueGreenStack: Sets up Code pipeline with ECS Blue Green Deployment. It uses S3 objects copied as part of
EcsWindowsBlueGreenClusterStack
and an ECR repository as sources. You will need to pass the ECR repo name where the image resides in cdk.json viaimageRepository
property.cdk synth PipelineEcsWindowsBlueGreenStack
cdk deploy PipelineEcsWindowsBlueGreenStack --require-approval never
One the pipeline stack is deployed, a code pipeline is created. It will take care of Blue/Green Deployment for your Ecs service using capacity provider autoscaling.
mvn package
compile and run testscdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
Enjoy!