Quantcast
Channel: Cloud Training Program
Viewing all articles
Browse latest Browse all 1902

Case Study: Blue-Green Deployments Using Elastic Beanstalk

$
0
0

In this blog, we are going to cover the case study on  Blue-Green Deployments Using AWS Elastic Beanstalk which we will be discussing in detail in our AWS Certified DevOps Engineer Professional FREE CLASS.

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.

Elastic Beanstalk DeploymentsTopics we will cover :

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.

Blue-Green Overview

To know more about Blue-Green deployment in AWS please read our blog on Blue-Green Deployment in AWS.

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.

Elastic Beanstalk advantages

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.

bean1

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.

bean2

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.

bean3

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

Architecture DiagramStep by Step Elastic Beanstalk Deployment Using Blue-Green

  1. If you don’t have a FREE AWS account, then create one from here Step by Step AWS FREE Tier Account
  2. Create an Elastic Beanstalk Application
  3. Create a Blue environment for PHP application
  4. Create a Green environment for updated PHP application
  5. Swap the URL’s from Blue to Green Environment

Step 1: Create an Elastic Beanstalk Application

  1. Search for Elastic Beanstalk and open it. Under application click on Create Application.
    Create Application
  2. Enter the Application name as Beanstalk_Blue-Green_Deployments, scroll down and click on Create Application.
    Enter the Application name
  3. Under Application you shall see our Application created successfully.Beanstalk Application

Step 2: Create a Blue Environment for PHP Application

  1. Under Application ‘Beanstalk_Blue-Green_Deployments’ environments Click on Create a new environment.
    Create environment
  2. Select the Web server environment and Click on Select.
    Enter the Environment name as blue-environment then Choose PHP as the platform.
    PHP Platform
  3. Choose Sample application and Click on Create Environment.
    Sample Application
  4. Once created Click on the URL generated by Elastic Beanstalk.
    Blue-env URL
  5. Now you shall see your PHP Application is Up and Running.
    PHP-application

Thus, we have successfully deployed our PHP application in blue-environment using Elastic Beanstalk.

Step 3: Create a Green Environment for Updated PHP Application.

  1. Under Application ‘Beanstalk_Blue-Green_Deployments’ environments Click on Create a new environment.
    Create Green Environment
  2. 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.
    Updated Version
  3. Click on the URL generated by Elastic Beanstalk.
    Green-env URL
  4. Now you shall see our Updated Version of PHP Application is Up and Running.Updated-PHP-application

Thus, we have successfully deployed our updated PHP application in the green-environment using Elastic Beanstalk.

Step 4: Swap the URL’s From Blue to Green Environment

  1. First, click on the blue-environment on the left panel. Under Actions click on Swap environment URLs.
    Swap
  2. Here, under select an environment to swap, select the Green Environment from the drop-down.
    Once selected the environment and click on Swap.
    Click on Swap
  3. Under Recent events, you shall see the Swapping CNAMEs for environments completed successfully.Swap Complete
    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.
  4. Now, click on the URL under green-environment and you shall be redirected to a new page.
    Swapped Application URL
  5. 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.Swapped Updated App

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.

Related/References

Next Task For You

This blog covers demo to demonstrate Blue/Green Deployment Using AWS Elastic Beanstalk which we will discuss in detail in our AWS DevOps FREE CLASS. If you want to begin your journey towards becoming an AWS Certified DevOps Engineer Professional by checking our FREE CLASS.

AWS DevOps Professional Certification Training

The post Case Study: Blue-Green Deployments Using Elastic Beanstalk appeared first on Cloud Training Program.


Viewing all articles
Browse latest Browse all 1902

Trending Articles