How does Blue/Green deployment work with AWS?
In one of our projects, we were working on the production upgrade of a large web application. The process involved upgrading multiple services and their components on different web application servers. With the traditional approach, the application had to be stopped for a certain maintenance window and redeployed with the latest code, services, and components. The main hurdle was to debug the application after upgrades and enable rollback to the previous stable version in case of failure. We provided an optimal workaround in time and stabilized an application's production environment within the maintenance window. This upgradation was possible with the adoption of Blue/Green deployment.
So what exactly is Blue/Green deployment?
Blue/Green deployment is a technique designed to reduce the complexity of production system upgrades. At its core, it involves running two identical environments called “blue” and “green.” The current environment is called "blue," and the other environment is the “green” environment which runs in parallel with the live environment. The main focus is to perform the upgradation process to the latest version by easily shifting the traffic between environments while releasing an upgrade. The process offers incremental updates to your production stack with zero downtime and less complexity for managing the rolling updates.
Blue/Green deployment methodology provides separate platforms for deploying your application infrastructure. It allows users to provide a green application environment in parallel to the existing blue environment. Furthermore, it helps minimize the deployment risk and provides ample time to perform validation on the new environment. If the validation test fails or there is any unexpected behavior, you can dispose of the environment without affecting the live blue production environment. Designing Blue/Green deployment-based CI/CD pipelines helps to minimize deployment complexities and ensure the same deployment procedure across all the environments, like dev, staging, and pre-prod.
AWS enables organizations to manage such deployments cost-effectively and at low risk during a major push to production.
What are the AWS services used in Blue/Green deployments?
AWS provides a number of services, such as AWS Elastic Beans, AWS Opsworks, AWS CloudFormation, Amazon Route 53, Elastic Load Balancing, EC2, RDS, and Auto Scaling, to automate application deployments. You can access these resources using API, SDKs, and configuration management tools like Ansible, Chef, and Puppet.
Amazon Route 53 - Route 53 is a highly available and managed DNS service that provides domain registration. It allows administrators to automatically modify endpoints (e.g., ELB) and assist in failover strategies. The traffic is redirected by simply updating DNS records in the hosted zone.
CodeDeploy - CodeDeploy enables automation of the deployment workflow. It is part of the new application lifecycle management (ALM) tools provided by AWS, including CodePipeline and CodeCommit. It also enables easy rollout of deployments across a fleet of AWS resources.
AWS CloudFormation - CloudFormation provides a JSON-based DSL for provisioning AWS resources. These JSON-formatted templates enable the provision of AWS resources such as EC2, Route 53, VPC, security groups, ELBs, RDS, S3, Auto Scaling, and IAM.
AWS Elastic Beanstalk - AWS Elastic Beanstalk is a simple and easy way to deploy an application on AWS. It supports Elastic load balancing and Auto-scaling, which help in Blue/Green deployments. This enables running different versions of applications and also provides out-of-the-box capabilities to switch from one environment to another by swapping the URLs.
AWS resources can be integrated into the CI/CD pipeline or when deploying applications. The application deployment architecture consists of a Route 53 DNS running with an Elastic load balancer. It also consists of containerized applications with multiple microservices running on the ECS. The AWS RDS simplifies the sharing of DB between two different environments enabling developers to adopt Blue/Green deployment.
How does Blue/Green deployment work with AWS?
DNS routing through record updates is a common approach to Blue/Green deployments. With DNS, you can easily switch traffic from the blue environment to the green and vice versa if rollback is necessary. Route 53 can perform a switch when bringing up the new “green” environment. The switch could consist of a single EC2 instance or an entire ELB. The resource record set must be updated to point to the domain/subdomain of the new instance or the new ELB. It works for various environment configurations if the endpoint is a DNS service or an IP address.
We can also use Route 53 with alias resource record sets as an alternative to this DNS approach. The traffic can be switched from blue to green by updating the alias record of the record set. You can easily roll back to blue deployment by updating the DNS record in case of an error.
Another approach to perform the Blue/Green switch is using the weighted distribution with Route 53. Here you can shift the traffic based on the weightage of the environment. Amazon Route 53 enables you to define a percentage of traffic for the green environment and gradually update the weights until the green environment carries the full production traffic. This method provides the ability to perform a canary analysis that gradually introduces a small percentage of production traffic to the new environment.
Blue/Green deployment operates at its best to enable high availability and continuous delivery. It provides a great way to minimize production impact and reduces risk by allowing testing prior to the release of a new version to the production environment. It simplifies the complexities involved, achieving zero-downtime deployments and a fast rollback mechanism. Cloud providers such as AWS allow us to easily create new environments and impart different options to implement Blue/Green deployments.
We will be discussing the tools, services, and strategies for Blue/Green deployment with AWS in detail in part 2 of this blog. Stay tuned!