This repo implements an approach for blue/green deploy in AWS described on this AWS whitepaper, which is the "Swap the Auto Scaling Group Behind Elastic Load Balancer"
There's a sample app which is used as our deployed application. Here's the following steps
- Build the sample app docker image and push it to AWS ECR;
- Download the state file (based on Terraform's approch from AWS S3 and set its content to a instance variable;
- Create a launch configuration if there isn't one already created;
- Create a classic load balancer if there isn't one already created;
- Create a new autoscaling group
- This autoscaling group will contain at max 2 instances. The user-data file will pull the lastest app docker image.
- Set the old autoscaling group max count to 0 and set its state to "standy by", which means that the load balancer won't send any requests to them, and will be "invisible" for it. Now, the new autoscaling group instances will receive traffic.
- Ask if rollback is necessary
- If yes, increase the min count of the old autoscaling group back to 1 and leave the standby state. For last, delete the new autoscaling group
- If no, simply delete the old autoscaling group
- Upload the updated state file back to AWS S3.