Blue/Green Deployment for Autoscaling Groups with CodePipeline, CodeBuild and CodeDeploy (Part 1/7)

Leon Jalfon
RhinOps by Sela
Published in
2 min readApr 28, 2020

In this 7-parts 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.

In this tutorial:

  1. Prerequisites
  2. Setup the initial environment
  3. Configure CodeBuild
  4. Configure CodeDeploy
  5. Configure CodePipeline
  6. Putting all together

The benefits of blue/green deployments

Blue/green deployment involves two production environments:

  • Blue is the active environment.
  • Green is for the release of a new version.

Here are some of the advantages of a blue/green deployment:

  • 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.

AWS CodeDeploy offers two ways to perform blue/green deployments on EC2:

  • 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.

References

--

--