In this blog, we are going to cover the case study on Blue-Green Deployments Using AWS Elastic Beanstalk.
The following diagram shows the logical components such as the Elastic Beanstalk Blue Environment consisting of Live traffic and Green Environment with updated version of the Application, Database and Cache Engines attached to both of them and shifting of live traffic from Blue to Green.

Before performing the blue-green deployment activity, we should understand the basic concepts of Blue-Green Deployments, Elastic Beanstalk, understand the deployments in Elastic Beanstalk.
Overview of Blue-Green Deployments
- A blue-green deployment is a management approach for releasing software code.
- Only one of the environments is live at a single time, where the live environment serves all the production traffic. For example, if blue is currently live then green would be idle and vice-versa.
- Blue-green deployments are usually utilized for consumer-facing applications and applications which have critical uptime requirements. The new code is delivered to the inactive environment, where it’s completely tested.

What Is AWS Elastic Beanstalk?
AWS Elastic Beanstalk is an easy-to-use AWS service for deploying and scaling web applications and services developed with Python, Ruby, Java, .NET, PHP, Node.js, Go, and Docker on familiar servers such as Apache, Passenger, Nginx, and IIS.
With Elastic Beanstalk, you just have to upload your code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, auto-scaling to application health monitoring. At the same time, you keep full control over the AWS resources powering your application and can access the underlying resources at any time.

Also Check: Our Previous Blog On AWS Cloudtrail vs Cloudwatch
Blue-Green Deployments in Elastic Beanstalk
AWS Elastic Beanstalk helps you to quickly deploy applications and manage them. It supports Auto Scaling and Elastic Load Balancing, the two of which empower blue-green deployment. It also makes it easier to run different adaptations of your application and provides developers a choice to exchange the environment URLs, encouraging blue-green deployment. To gain in-depth knowledge check our blog on AWS Elastic Beanstalk.

Elastic Beanstalk provides an environment URL when the application is up and running. Then, the green environment is spun up with its own environment URL. At this point, two environments are up and running, but only the blue environment is serving production traffic.

To promote the green environment to serve production traffic, you go to the environment’s dashboard within the Elastic Beanstalk console and choose the Swap Environment URL from the Actions menu. Elastic Beanstalk performs a DNS switch, which usually takes a couple of minutes.

Base Scenario (Use Case)
AWS Elastic Beanstalk performs normal deployments in the current production environment. Due to this, the application will be unavailable to users until the update is complete. This downtime can be avoided by performing a blue/green deployment. In this scenario, we will do the following steps to overcome this issue

Read More: What is Amazon Kinesis?
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 PHP application
- Create a Green environment for updated PHP application
- Swap the URL’s from Blue to Green Environment
Step 1: Create an Elastic Beanstalk Application
- Search for Elastic Beanstalk and open it. Under application click on Create Application.
- Enter the Application name as Beanstalk_Blue-Green_Deployments, scroll down and click on Create Application.
- Under Application you shall see our Application created successfully.
Step 2: Create a Blue Environment for PHP Application
- Under Application ‘Beanstalk_Blue-Green_Deployments’ environments Click on Create a new environment.
- Select the Web server environment and Click on Select.
Enter the Environment name as blue-environment then Choose PHP as the platform. - Choose Sample application and Click on Create Environment.
- Once created Click on the URL generated by Elastic Beanstalk.
- Now you shall see your PHP Application is Up and Running.
Also Check: What is SDLC Automation in AWS
Thus, we have successfully deployed our PHP application in blue environment using Elastic Beanstalk.
Step 3: Create a Green Environment for Updated PHP Application.
- Under Application ‘Beanstalk_Blue-Green_Deployments’ environments Click on Create a new environment.
- Select the Web server environment and Click on Select.
Enter the Environment name as green-environment then choose PHP as the Platform.
Under application code, choose Upload your code, and upload the updated code of PHP application (To download updated code click here)and click on Create environment.
- Click on the URL generated by Elastic Beanstalk.
- Now you shall see our Updated Version of PHP Application is Up and Running.
Thus, we have successfully deployed our updated PHP application in the green environment using Elastic Beanstalk.
Also Check: How to Use AWS Command Line Interface. Click here
Step 4: Swap the URL’s From Blue to Green Environment
- First, click on the blue-environment on the left panel. Under Actions click on Swap environment URLs.
- Here, under select an environment to swap, select the Green Environment from the drop-down.
Once selected the environment and click on Swap. - Under Recent events, you shall see the Swapping CNAMEs for environments completed successfully.
Note: Now you shall see that the URLs are swapped so the URL under the blue environment is by name green-environment and the URL under green environment is changed to blue-ones. Basically, the URLs are interchanged. - Now, click on the URL under green-environment and you shall be redirected to a new page.
- Now Clicking on the URL (which was the URL for the blue_environment), you shall notice the content of green_environment instead i.e. even hitting the URL of sample/blue PHP application you are getting the output page of Updated Version of PHP application.
Thus, we have successfully implemented the blue-green deployments using Elastic Beanstalk. By swapping the URL’s again you can roll back to the previous version of your application.