![]()
One important way to assess an application is by how often it has periods when it’s not working or available for users to use. This downtime helps us understand how reliable and usable the app is. Another crucial factor in determining if an app is good is how often it’s not working or unavailable.
In this blog post, we’ll talk about Blue-Green Deployment, which helps achieve zero downtime. As developers, we’ve all had times when a new version of our app is slow or buggy, forcing us to roll back to a stable version. But rolling back isn’t easy.
Rolling back means redeploying an older version from scratch, which takes a lot of time and can make us lose thousands of customers in real time. Even if the bug is small, we don’t have time to fix it and return to the stable version quickly. So how can we solve this problem?
Table of Contents
- Overview of Blue-Green Deployments
- Achieving Blue-Green Deployment via AWS Tools & Services
- Advantages of Blue-Green Deployments
- Blue-Green Testing Model
- Disadvantages of Blue-Green Deployments
- Alternatives for Blue-Green Deployment
- Case Study: Blue-Green Deployments Using Elastic Beanstalk
- Frequently Asked Questions
Overview of Blue-Green Deployments
Blue-green deployments are a method to reduce risks when updating software. They allow for updates without causing downtime and provide a way to go back to a previous version if needed.
Here’s how it works: You have two nearly identical environments. One is called ‘blue‘ and represents the current live version of your app. The other is ‘green,’ where you test new updates. Once the green environment is proven to work well, you switch user traffic from blue to green. If any issues arise, you can quickly switch back to blue.
These environments can be on different hardware or virtual machines. A load balancer directs user traffic between them, ensuring a smooth transition. This setup helps maintain a stable service while introducing new features or fixes.
Achieving Blue-Green Deployment via AWS Tools & Services
Various services in the AWS ecosystem support blue-green deployment strategy and help automate your deployment:
1) AWS Elastic Beanstalk:
AWS Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services. It supports various AWS services like Auto Scaling and Elastic Load Balancing, making it simpler to manage application deployments.
Elastic Beanstalk facilitates blue-green deployments by allowing you to swap environment URLs between different versions of your application. This means you can seamlessly transition production traffic from the current (blue) environment to the new (green) environment with minimal downtime.
Efficient Deployment with AWS Elastic Beanstalk
In a typical situation, AWS Elastic Beanstalk updates applications directly in the current production environment, causing downtime for users until the update finishes. To avoid this downtime, we can use a blue/green deployment approach. Here’s how we tackle this problem:.
2) Amazon Route 53:
Amazon Route 53 is a DNS (Domain Name System) service provided by AWS. It helps manage domain names, route internet traffic to your resources, and perform health checks to ensure your applications are running smoothly. For blue-green deployments, Route 53 allows you to control traffic by updating DNS records, making it easy to switch between different versions of your application.
3) Elastic Load Balancing (ELB):
Elastic Load Balancing (ELB) is a service that automatically distributes incoming application traffic across multiple targets, such as Amazon EC2 instances. It improves the availability and fault tolerance of your applications by automatically routing traffic away from unhealthy instances. ELB integrates seamlessly with AWS Auto Scaling, which adjusts the number of EC2 instances based on traffic demand, ensuring your application can handle varying workloads without downtime.
4) Auto Scaling:
Auto Scaling automatically adjusts the number of EC2 instances in response to changing demand for your application. You can use launch configurations to define how instances are launched in an Auto Scaling group. This flexibility allows for the smooth implementation of blue-green deployments.
In a typical setup, a blue Auto Scaling group handles production traffic, while a green group is prepared with new code for deployment. When ready, the green group is attached to the load balancer to start serving traffic, utilizing algorithms that direct new requests to it.

Scaling up the green Auto Scaling group involves placing blue instances in a Standby state or terminating them. Standby preserves their configurations for quick reactivation if a rollback to the blue environment is necessary.
Launch configurations specify details such as AMI ID, instance type, security groups, and block device mappings. Each Auto Scaling group can have only one launch configuration, set at creation and unmodifiable thereafter.

To deploy a new version in the green environment, update the Auto Scaling group with the new launch configuration and scale it up. Then, scale down to the original size once you are confident in the deployment’s stability.
For rollbacks, revert to the old launch configuration and follow the steps in reverse. Utilize the Standby state to reactivate instances quickly if needed.
Alternatives for Blue-Green Deployment
Canary Release: This technique reduces the risk of deploying a new software version. It does this by gradually rolling out the change to a small group of users first. If everything works fine, the new version is then rolled out to everyone.
Canary Testing: If the new version (green environment) has issues, the old version (blue environment) remains unaffected. You can easily switch users back to the blue environment, minimizing downtime and the impact on users.
Step-by-Step Elastic Beanstalk Deployment Using Blue-Green
- If you don’t have a FREE AWS account, then create one from here Step-by-step AWS FREE Tier Account
- Create an Elastic Beanstalk Application
- Create a Blue environment for the PHP application
- Create a Green environment for updated PHP application
- Swap the URLs from Blue to Green Environment.
Step 1: Create an Elastic Beanstalk Application
- Login to the AWS Console and search for Elastic Beanstalk. Under Environment, click on Create Environment.

- Enter the Application name as Beanstalk_Blue-Green_Deployment and scroll down.

- Select Platform as Docker, Let everything default and Click on Next.

- Select role: Create and use a new service role
- EC2 instance profile: Ec2instancerole
- Click on Skip to review and then click on Submit

- Under Applications, you will see our Application has been created.

Note: Now, we have successfully created our Blue-Green Deployment Application. In further steps, we shall create two different environments, one for the PHP application and the other for the updated version of our same PHP Application.
Step 2: Create a Blue Environment for PHP Application
Note: After creating the application, we shall create two different environments based on the same platform. Here, we will have a PHP Platform for both environments. In this section, we are going to create a blue environment with a PHP application that will be our current production environment with live traffic. Let’s get started.
- Now, click on the Application name and open it.

- Under Application ‘Beanstalk_Blue-Green_Deployments’ environments Click on Create a new environment.

- Select the Web server environment.
- Enter the Environment name as blue-environment.
Note: Here, are leaving the domain blank because it will be auto-generated after the environment is created. - Scroll down, select Managed Platform, and Choose PHP as the platform. Here, we are choosing PHP as a platform only for this lab.

- Choose Sample application and Click on Next. For Configuration presets as Single instance Here you can also upload your code, but we are selecting the Sample application for now.

- Select the EC2InstanceRole under EC2 Instance and click on Skip to review

- Scroll down, Review everything, and click on Submit.
- Please wait, as it will take 5 – 10 minutes to complete the setup of creating the blue-environment.

- The blue environment has successfully launched; you will see this screen. Now check the Recent Events, and then click on the URL generated by Elastic Beanstalk.

- Now you will see that your PHP Application is Up and Running.

Thus, we have successfully deployed our PHP application in the blue environment using Elastic Beanstalk.
Also Check: What is SDLC Automation in AWS
Step 3: Create a Green Environment for Updated PHP Application.
Note: Let’s update our code and deploy it for live traffic, while our current traffic hits the blue environment URL. We’ll create a green environment with the updated code and shift the traffic to this new version. In this section, we’ll deploy our latest PHP application in the green environment.
In this section, we would require an updated version of the PHP code to deploy, Click on the following link and save it on your laptop as php-v2.zip
- Now click on our Application name to create a new environment.

- Click on Create a new environment.

- Select Web server Environment.
- Under Environment name, enter the name as green-environment

- Scroll down, select Managed Platform, and under Choose a Platform select PHP.
Now select Upload your code enter the Version label as Sample-Version-2 or any name you want and click on Choose file.

- Select the zip file that we downloaded earlier and click on Open.

- Once the zip file is uploaded successfully, click on Next.

- Select the EC2InstanceRole under EC2 Instance and click on Skip to review.
Scroll down, Review everything, and click on Submit.- Now wait for 5 minutes until the environment is deployed successfully.
Back on the EC2 instances console, you shall see the instance is deployed by the name green-environment.
Once Completed, your screen will look like this, Check the recent events and Click on the URL created by Beanstalk.
- Now you will see that our Updated Version of the PHP Application is Up and Running.

Thus, we have successfully deployed our updated PHP application in a green environment using Elastic Beanstalk.
Step 4: Swap the URLs From Blue to Green Environment
Note: Here we have two environments, the Blue environment with sample PHP code and the Green environment with Updated PHP code and we are going to swap the URLs from Blue to Green.
- First, click on the blue-environment on the left panel.

- Click on Actions and Swap environment domain.

- Here, under select an environment to swap, select the Green Environment from the drop-down and click on Swap.

- Under Recent Events, you shall see the Swapping CNAMEs for environments completed successfully.

- Once the URLs are swapped, click on the environments in the left menu bar.
Note: Now you shall see that the URLs are swapped so the URL under the blue environment is named green-environment and the URL under the green environment is changed to blue-ones. The URLs are interchanged. - Now, click on the URL in front of green-environment and you will be redirected to an updated version page.

Now Clicking on the URL in front of the blue-environment, you will be redirected to an old page.(Notice the change in URLs and Applications.)
Note: Thus, we have successfully implemented the blue-green deployments using Elastic Beanstalk. By swapping the URL’ again you can roll back to the previous version of your application.
Frequently Asked Questions
Q1) How does Blue-Green Deployment minimize downtime during updates?
A) It uses two environments (blue for live, green for testing). Once the green version is stable, traffic switches to it, minimizing downtime. If issues arise, traffic reverts to blue.
Q2) What challenges does Blue-Green Deployment face and how can they be mitigated?
A) Challenges include data migration, setup complexity, costs, and user interruptions. Mitigation involves using automated tools like AWS CloudFormation, thorough testing with Amazon CloudWatch, and careful data migration and rollback planning.
Q3) How do AWS services facilitate Blue-Green Deployment?
A) AWS Elastic Beanstalk simplifies deployment and environment swaps; Route 53 manages DNS to route traffic; Auto Scaling adjusts instances for demand, ensuring smooth transitions and quick reactivations if needed.
Q4: When might Blue-Green Deployment be less advantageous than Canary Releases?
A) It's less advantageous when maintaining parallel environments is costly, data migration is complex, or user transactions are sensitive to interruptions. Canary Releases allow gradual, controlled updates, reducing widespread risk.
Q5) How does Amazon CloudWatch enhance Blue-Green Deployments?
A) It monitors performance and health, sets alarms for real-time issue detection, analyzes logs for troubleshooting, and maintains visibility and performance tracking, ensuring application stability and reliability.
Related/References
- What is AWS Elastic Beanstalk
- What is AWS Route53 and it’s key features
- Overview of Amazon Web Services & Concept
- How does the AWS Load Balancer Work?
- AWS Management Console Walkthrough
- AWS Certificate Manager
- AWS Fargate (Serverless Containers)
- Amazon DynamoDB: Fast and Scalable NoSQL Database
Next Task For You
Join our FREE Informative Class on How to Get High-Paying Jobs in AWS CLOUD, even if you’re a beginner with no experience or coding knowledge. Click on the image below to get started.

