Elevating Your Deployment Game with Elastic Beanstalk

Elevating Your Deployment Game with Elastic Beanstalk

ยท

6 min read

Hey Devops amigos! Today, we're diving into the world of faultless deployments, a crucial aspect of running a software company. Imagine a world where deploying code is smooth, with minimal risk and maximum availability. Well, guess what? I am making that a reality in this tasks.

Overview

Running a software company involves intricate systems and, during deployments, these systems dance delicately, juggling multiple moving parts. The risk is real, but fear not! Our lab today is here to equip you with the skills to navigate these complexities. We'll be deploying multiple version updates of an application in an environment that's load-balanced and auto-scaled.

Tasks Objectives

By the end of these tasks, you'll be a deployment maestro, capable of:

  1. Building Elastic Beanstalk Applications and Environments:

    • We'll start by understanding how to set up applications and environments using Elastic Beanstalk, a powerful service that makes deploying and managing applications a breeze.
  2. Performing Rolling Deployments on EC2 Resources:

    • Learn the art of the low-friction rolling deployment. We'll deploy the first update seamlessly, ensuring minimal impact on your underlying EC2 resources.
  3. Executing Blue-Green Deployments with Elastic Beanstalk:

    • Take your skills to the next level with blue-green deployments. We'll create a separate environment to run the new version of the application. A DNS cutover will gracefully switch incoming traffic to the new environment, ensuring zero-downtime updates.
  4. Minimizing Costs through Cleanup:

    • We'll be responsible cloud practitioners. Learn how to tidy up after blue-green deploys, minimizing costs and keeping your cloud environment pristine.

Before and After Architecture Visuals

๐Ÿ’ก
Before starting you need to have a basic web app.Login to your AWS account with credentials

Task 1: Creating Your Elastic Beanstalk Playaground

In this task, we will setup Elastic Beanstalk application and environment.

Configuring Environment

  • Open the AWS Management Console and enter "Beanstalk" in the search bar. Click on Elastic Beanstalk under Services.

  • Click on "Create Application" to kick off the setup.

  1. Fill in the application details.
  • Application Name: Enter "My App."

  • Platform: Select your preferred platform (e.g., Node.js).

  • Version label: Call it "my-app-v1."

  • Source code origin: Choose "Upload your code."

  • Source code origin: Select "Local file" and upload the "v1.zip"(I have my html, css, JS files under this zip) file you downloaded earlier.

  1. Change the Presets to Custom configuration and click Next.

  2. Set up service access.

    • Service role: Use an existing service role named "aws-elasticbeanstalk-service-role."

    • EC2 instance profile: Choose "aws-elasticbeanstalk-ec2-profile."

  3. Configure networking, database, and tags.

    • VPC: Select the non-default VPC with a CIDR block of 10.0.0.0/16.

    • Instance subnets: Pick the private subnet with CIDR block 10.0.1.0/24.

    • Database subnets: Select the two private subnets with CIDR blocks 10.0.1.0/24 and 10.0.2.0/24.

  4. Configure instance traffic and scaling.

    • EC2 security groups: Choose the default security group.

    • Environment type: Select "Load balanced."

    • Instance types: Pick only "t2.micro."

    • Load balancer subnets: Choose the two public subnets with CIDR blocks 10.0.100.0/24 and 10.0.101.0/24.

  5. Configure updates, monitoring, and logging.

    • System: Choose "Enhanced" for real-time monitoring.

    • Deployment policy: Select "Rolling" with a batch size of 30.

Review the configurations and click "Submit." Now, watch the magic unfold as Elastic Beanstalk creates your environment. This might take a few minutes.

Once complete, click on the environment's URL to view the deployed application.

Task 2: Rolling into the Future - A Seamless Deployment

๐Ÿ’ก
I did some changes in my code. A minor change, for example like <p> this is version 2 </p>

Head over to your Elastic Beanstalk environment and locate the magic button - "Upload and Deploy."

  1. In the "Upload and Deploy" form, let's configure the settings for the grand reveal:

    • Upload application: Click "Choose File" and select the "v2.zip" file you modified to version 2.

    • Version label: Name it "my app v2."

  2. Click "Deploy" to experience Elastic Beanstalk's rolling deployment, where instances take turns upgrading to a new version. Temporary unavailability may occur during the switch from v1 to v2, especially with a single instance, but more instances reduce the risk of outages.

  3. Wait patiently until the deployment completes, and confirm that your environment reports v2 is running.

    Here you can check my app v2 has been deployed successfully

    Here are some key takeaways:

    • No new instances are created; the new version gracefully replaces the old on existing instances.

    • The maximum available capacity for serving traffic is momentarily reduced during the upgrade, potentially causing brief service outages, especially with a single instance.

    • Keep in mind that during multi-batch upgrades, old and new versions might coexist momentarily.

Task 3: Embracing the Future with Blue-Green Deployment

๐Ÿ’ก
I did some changes in my code. A minor change, for example like <p> this is version 3 </p>
  1. Cloning the Environment

    • In Elastic Beanstalk, navigate to the environment view of your current environment (MyApp-env).

    • Click on "Actions" in the upper-right corner and select "Clone Environment" to create a new environment, our green paradise.

    • On the Clone environment form, name the new environment:

      • Environment name: Myapp-env-1 (Leave other values as default)
    • Click "Clone" and wait patiently for the new environment to take shape. It might take up to 5 minutes. Ensure the Health status turns to Ok before moving forward.

  2. Rolling Deployment to Green

    • In the "Upload and Deploy" form:

      • Upload application: Choose the v3.zip file you modified to version 3.

      • Version label: Name it "my app v3."

    • Click "Deploy" and watch as Elastic Beanstalk performs a seamless rolling deployment to our fresh, green environment. Since the environment is currently unused, no need to worry about availability and performance concerns.

    • Wait until the rolling deployment completes, and confirm that the Running Version is now "my app v3."

Task 4: DNS Ballet - Switching Traffic with Grace

It's time to perform a DNS swap, a graceful ballet of directing traffic seamlessly between environments.

  1. Initiating the DNS Swap

    • In the Elastic Beanstalk environment console, select your green environment (MyApp-env-1).

    • Click on "Actions," then choose "Swap environment domain."

    • In the Swap environment domain form:

      • Environment name: MyApp-env (Select the blue environment)
    • Click "Swap" and watch the magic unfold. The swap typically completes in under ten seconds. You'll see the Health status turn to Ok, and the most recent event will read "Completed swapping CNAMEs."

  2. Verification:

    • Verify that the browser loads version 3 of the app
  3. Remember these key points:

    • The maximum number of instances during deployment is twice the target number, with both environments fully functional.

    • The minimum number of instances serving the application never falls below the target.

    • Rolling back to the old version is easy since the blue environment remains unaltered.

    • Old and new versions are never served simultaneously to new clients.

Task 5: Tidying Up - Saying Farewell to the Old

Terminate everything that you have to avoid costs!!!!!

Conclusion

In these tasks, you created a web application environment using AWS Elastic Beanstalk. The environment is configured for high availability and to perform rolling updates when new versions of the application are deployed.

If you like this blog, hit that like and follow buttons for more content like this.
Follow me on Linkedin.

Thank you for paying visit to my blog!!!

Did you find this article valuable?

Support Farhan's Scripted Explorations by becoming a sponsor. Any amount is appreciated!