AWS with Terraform (Day 17)
Blue-Green Deployment on AWS Elastic Beanstalk Using Terraform
Seamless Releases. Zero Downtime. Maximum Confidence.
Today’s focus was on one of the most essential real-world DevOps deployment strategies: Blue-Green Deployment using AWS Elastic Beanstalk + Terraform. I cloned the repository, applied file permissions, packaged application versions, deployed both blue & green environments, and even executed the final DNS swap. Everything worked smoothly end-to-end.
This blog captures the full journey.
What is Blue-Green Deployment?
Blue-Green deployment maintains two identical environments:
-
Blue → Active production environment
-
Green → Staging/testing environment
You deploy updates to Green, validate everything, then swap traffic to Green using DNS/CNAME.
Rollback? One click. Swap back.
No downtime, no user impact, no surprises.
Why Elastic Beanstalk + Terraform?
Combining Elastic Beanstalk with Terraform provides:
Automation
Infrastructure is codified — no manual point-and-click deployments.
Safe Deployment Flow
Changes land on the staging environment first.
Instant Rollbacks
Traffic swap back is immediate.
Environment Isolation
Each environment stays identical, making the swap predictable.
Architecture Summary
-
Package app versions (v1 & v2) → store in private S3 bucket.
-
Create two Beanstalk environments (
blueandgreen). -
Deploy v1 to blue (live) and v2 to green (staging).
-
Test the green environment thoroughly.
-
Swap environment CNAMEs → green becomes live.
-
Rollback by swapping again if required.
Repo Structure I Worked With Today (Day-17)
I granted permissions to the scripts, zipped the app versions, and applied the Terraform config with:
Both environments were created successfully, and the CNAME swap executed perfectly.
Key Terraform Components
S3 (Private)
Stores application .zip files.
Elastic Beanstalk Application
Holds metadata and version info.
Blue & Green Environments
Each includes:
-
Solution stack
-
Instance profile & IAM
-
Autoscaling config
-
Load balancer health checks
-
Deployment policies
Outputs
-
Environment names
-
URLs (CNAMEs)
-
Instructions for swapping URLs
DNS Swap & Verification
Once the green environment was validated:
-
Swapped CNAME in Elastic Beanstalk console
-
Traffic instantly moved to the green environment
-
No downtime
-
Smooth transition
Rollback was tested as well — working perfectly.
Best Practices I Followed Today
✔ Keep S3 buckets private
✔ Match blue/green environment configurations
✔ Use correct health check paths (/ on port 80)
✔ Plan DNS propagation
✔ Tag every resource
✔ Test rollback before declaring success
✔ Avoid long-lived idle environments unless required
Key Learnings from Day-17
-
Blue-Green deployment drastically reduces release risk.
-
Terraform makes environment provisioning predictable and repeatable.
-
Elastic Beanstalk handles a lot of complexity behind the scenes.
-
DNS swapping is one of the safest changes when implemented correctly.
-
Always validate the green environment thoroughly before swap.
-
Rollback strategy should be tested—not assumed.
Diagram
Final Thought
“Deploy to a staging copy, validate thoroughly, and swap when ready — minimal downtime, maximum confidence.”
This strategy is battle-tested and one of the cleanest ways to release updates in production without impacting users.
Day 17 complete. On to the next challenge.
Here is the repo link: https://github.com/Mo-Adnan-Mo-Ayyub/Aws-with-Terraform
Here is the session link:
Comments
Post a Comment