Skip to main content

Command Palette

Search for a command to run...

Day 17: AWS Elastic Beanstalk Blue-Green Deployment Demo

AWS Elastic Beanstalk to achieve zero-downtime deployments through blue-green deployment strategy.

Published
5 min read
N

I’m a Cloud & DevOps Engineer passionate about building reliable, scalable, and automated cloud infrastructures. I work extensively with AWS, Kubernetes, Terraform, Docker, and CI/CD pipelines to deliver production-ready environments.

My journey started in technical troubleshooting, where I gained strong root-cause analysis and system diagnostic skills. Transitioning into cloud engineering, I have built 3-tier microservices architectures, automated VPCs using Terraform, and containerized legacy applications for performance and portability.

I enjoy solving real-world problems, optimizing cloud cost and performance, and creating automated workflows that reduce manual effort. I’m continuously learning and applying best practices in DevOps, IaC, and cloud security.

Core Skills: AWS • Kubernetes • Docker • Terraform • CI/CD • Linux • Networking • Monitoring • Automation • Troubleshooting

Looking For: Cloud Engineer | DevOps Engineer | SRE (Junior/Mid-level) roles where I can build, automate, and scale cloud workloads.

This demo replicates the Azure App Service deployment slot functionality using AWS Elastic Beanstalk to achieve zero-downtime deployments through blue-green deployment strategy.

🎯 What This Demo Does

This Terraform project creates:

  • Blue Environment (Production) - Running Application v1.0

  • Green Environment (Staging) - Running Application v2.0

  • Complete infrastructure with load balancers, auto-scaling, and health checks

  • Ability to instantly swap traffic between environments with zero downtime

🏗️ Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                  Elastic Beanstalk Application              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ┌──────────────────────┐      ┌──────────────────────┐   │
│  │  Blue Environment    │      │  Green Environment   │   │
│  │  (Production)        │      │  (Staging)           │   │
│  ├──────────────────────┤      ├──────────────────────┤   │
│  │  Version 1.0         │      │  Version 2.0         │   │
│  │  Load Balancer       │      │  Load Balancer       │   │
│  │  Auto Scaling        │      │  Auto Scaling        │   │
│  │  Health Checks       │      │  Health Checks       │   │
│  │                      │      │                      │   │
│  │  URL: my-app-blue... │      │  URL: my-app-green..│   │
│  └──────────────────────┘      └──────────────────────┘   │
│           │                              │                 │
│           └──────────────┬───────────────┘                 │
│                          │                                 │
│                 CNAME Swap (Instant)                       │
└─────────────────────────────────────────────────────────────┘

📋 Prerequisites

  1. AWS Account with appropriate permissions

  2. Terraform (>= 1.0) installed

  3. AWS CLI configured with credentials

  4. PowerShell (for packaging scripts)

  5. Node.js (optional, for local testing)

Blue Environment (Production): http://my-app-bluegreen-blue-xxxxxx.elasticbeanstalk.com

Green Environment (Staging): http://my-app-bluegreen-green-xxxxxx.elasticbeanstalk.com

🔵 Testing the Blue Environment (Production - v1.0)

Visit the Blue environment URL. You should see:

  • Version 1.0 displayed prominently

  • Blue color scheme

  • "PRODUCTION" badge

  • Basic feature set

🟢 Testing the Green Environment (Staging - v2.0)

Visit the Green environment URL. You should see:

  • Version 2.0 displayed prominently

  • Green color scheme

  • "STAGING" badge

  • New features listed:

    • Refreshed UI with modern design

    • Improved performance

    • Enhanced security features

    • Better analytics tracking

    • Critical bug fixes

🔄 Performing the Blue-Green Swap

Once you've verified the Green environment is working correctly, perform the swap:

.\swap-environments.ps1

The script will:

  1. Automatically read environment names from Terraform

  2. Ask for confirmation

  3. Perform the CNAME swap

  4. Display status and next steps

Option 2: Using AWS CLI Directly

aws elasticbeanstalk swap-environment-cnames \
  --source-environment-name my-app-bluegreen-blue \
  --destination-environment-name my-app-bluegreen-green \
  --region us-east-1

Option 3: Using AWS Console (Step-by-Step with Screenshots)

Step 1: Open the AWS Console

Step 2: Select Your Application

  • In the Applications list, click on my-app-bluegreen

  • You'll see both environments listed (Blue and Green)

Step 3: Choose an Environment to Swap

  • Click on either the Blue or Green environment name

  • (You can start from either environment - the result is the same)

Step 4: Access the Swap Action

  • Click the Actions button (top right)

  • From the dropdown menu, select Swap environment URLs

Step 5: Select the Target Environment

  • A dialog will appear asking which environment to swap with

  • Select the other environment from the dropdown

    • If you started from Blue, select Green

    • If you started from Green, select Blue

Step 6: Confirm the Swap

  • Review the warning message about traffic redirection

  • Click the Swap button to confirm

Step 7: Monitor the Swap

  • The environments will show "Updating" status

  • Wait 1-2 minutes for the swap to complete

  • Both environments will return to "Ok" (green) status

Step 8: Verify Success

  • Note that the URLs have been swapped

  • The environment names stay the same, but the URLs are exchanged

  • Visit both URLs to confirm the swap worked

✅ Verifying the Swap

After the swap completes (1-2 minutes), verify:

  1. Blue URL now shows v2.0:

     Visit: <blue-url>
     Expected: "Welcome to Version 2.0 - Green Environment"
    

Green URL now shows v1.0:

Visit: <green-url>
Expected: "Welcome to Version 1.0 - Blue Environment"
  1. Zero Downtime: Your production traffic seamlessly moved from v1.0 to v2.0!

🔙 Rolling Back

If you need to rollback to the previous version:

# Simply run the swap again!
.\swap-environments.ps1

The swap is instant and bidirectional - the previous production environment is still running the old version.

📊 Key Features Demonstrated

1. Zero-Downtime Deployment

  • Traffic switches instantly at the DNS level

  • No service interruption

  • Users experience seamless transition

2. Easy Rollback

  • Previous version still running in the other environment

  • Instant rollback by swapping again

  • No need to redeploy

3. Safe Testing

  • Test new version in production-like environment

  • Same infrastructure configuration

  • Isolated from production traffic

4. Production Parity

  • Both environments identical

  • Same instance types, scaling, and configuration

  • Eliminates "works on staging" issues

🏷️ Resource Tagging

All resources are tagged with:

  • Project: BlueGreenDeployment

  • Environment: Demo

  • ManagedBy: Terraform

💰 Cost Considerations

This demo creates:

  • 2 Application Load Balancers (~$16/month each)

  • 2-4 EC2 instances (depending on auto-scaling)

  • S3 bucket for application versions

  • CloudWatch monitoring

Estimated Monthly Cost: $50-100 USD (depending on instance types and usage)

To minimize costs:

  • Use t3.micro instances (default)

  • Destroy resources when not in use: terraform destroy

  • Set appropriate auto-scaling limits

🧹 Cleanup

To destroy all resources:

terraform destroy

Warning: This will delete:

  • Both Elastic Beanstalk environments

  • Application Load Balancers

  • EC2 instances

  • S3 bucket (if empty)

  • All associated resources

🎓 What I Learned

✅ How to implement blue-green deployments on AWS
✅ Elastic Beanstalk environment management
✅ Zero-downtime deployment strategies
✅ Infrastructure as Code with Terraform
✅ AWS CLI for environment swapping
✅ Production-safe deployment practices

🎥 Day 17 Video ( link )


🚀 Conclusion

This project provided deep hands-on experience with AWS elasticbeanstalk and Terraform.
I gained a stronger understanding of real-world cloud architecture challenges.


🔖 Tags

#30DaysOfAWSTerraform #AWS #Terraform #elasticbeanstalk #blue&grean #DevOps #CloudComputing #IaC