In this tutorial we will create an initial environment composed by an autoscaling group with two ubuntu machines behind a load balancer, then we will create a CI/CD pipeline to provide blue/green deployments using CodeBuild, CodeDeploy and CodePipeline.
- Prerequisites
- Setup initial environment
- Configure CodeBuild
- Configure CodeDeploy
- Configure CodePipeline
- Putting all together
Blue/green deployment involves two production environments:
- Blue is the active environment.
- Green is for the release of a new version.
- You can perform testing on the green environment without disrupting the blue environment.
- Switching to the green environment involves no downtime. It only requires the redirecting of user traffic.
- Rolling back from the green environment to the blue environment in the event of a problem is easier because you can redirect traffic to the blue environment without having to rebuild it.
- You can incorporate the principle of infrastructure immutability by provisioning fresh instances when you need to make changes. In this way, you avoid configuration drift.
- In the first approach, AWS CodeDeploy makes a copy of an Auto Scaling group. It, in turn, provisions new Amazon EC2 instances, deploys the application to these new instances, and then redirects traffic to the newly deployed code.
- In the second approach, you use instance tags or an Auto Scaling group to select the instances that will be used for the green environment. AWS CodeDeploy then deploys the code to the tagged instances.