Introduction
In modern DevOps practices, ensuring zero downtime deployments is critical for user experience. One proven technique to achieve this is Blue-Green Deployment. This strategy reduces downtime and risks by running two identical environments—Blue (current) and Green (new)—and switching traffic between them using a load balancer.
In AWS, EC2 instances with an Application Load Balancer (ALB) provide a simple yet powerful setup for Blue-Green deployments.
What is Blue-Green Deployment?
Blue-Green deployment is a release management strategy where you maintain two production environments:
- Blue Environment: The currently live version of your application.
- Green Environment: The new version you want to deploy.
Traffic is gradually (or instantly) switched from Blue to Green, ensuring minimal downtime. If issues occur, you can roll back by redirecting traffic back to Blue.
Architecture Overview
Here’s how it looks in AWS:
- EC2 Auto Scaling Groups (ASG)
- One ASG runs the Blue environment.
- Another ASG runs the Green environment.
- Application Load Balancer (ALB)
- Routes traffic to either Blue or Green target groups.
- Supports weighted routing for gradual traffic shifting.
- Deployment Process
- Deploy the new version in the Green environment.
- Test internally using ALB rules.
- Switch ALB traffic from Blue → Green once validated.
Step-by-Step Implementation
1. Setup ALB with Target Groups
- Create an Application Load Balancer.
- Define two target groups:
- TG-Blue → maps to Blue EC2 instances.
- TG-Green → maps to Green EC2 instances.
2. Launch EC2 Instances in ASGs
- Blue ASG → runs your current application version.
- Green ASG → runs the new version.
Each ASG registers its instances into its respective ALB target group.
3. Routing Rules in ALB
- Default listener rule → send 100% traffic to TG-Blue.
- For testing, you can create rules to route traffic from a specific path/host header to TG-Green.
4. Deployment Process
- Deploy the new release into Green ASG.
- Test it internally (using test headers or paths).
- Update ALB listener rule to shift traffic:
- Option A: Instant switch → 100% to Green.
- Option B: Weighted switch → gradually move traffic (e.g., 20% Green, 80% Blue).
5. Rollback (if needed)
If something breaks, simply update the ALB listener to send traffic back to Blue.
Benefits of Blue-Green Deployment
✔ Zero downtime during deployments
✔ Quick rollback in case of failure
✔ Safer way to test new versions in production
✔ Works well with CI/CD pipelines (CodeDeploy, Jenkins, GitHub Actions, etc.)
Terraform Example (Snippet)
resource “aws_lb_target_group” “blue” {
name = “blue-tg”
port = 80
protocol = “HTTP”
vpc_id = var.vpc_id
}
resource “aws_lb_target_group” “green” {
name = “green-tg”
port = 80
protocol = “HTTP”
vpc_id = var.vpc_id
}
resource “aws_lb_listener_rule” “blue_green” {
listener_arn = aws_lb_listener.http.arn
action {
type = “forward”
forward {
target_group {
arn = aws_lb_target_group.blue.arn
weight = 50
}
target_group {
arn = aws_lb_target_group.green.arn
weight = 50
}
}
}
condition {
host_header {
values = [“example.com”]
}
}
}
This example splits traffic 50/50 between Blue and Green, and you can adjust weights to control rollout speed.
Conclusion
Blue-Green deployment on AWS with EC2 and ALB is a simple yet powerful way to achieve zero-downtime deployments. By leveraging ALB target groups and routing rules, teams can deploy safely, roll back instantly, and improve customer trust in production systems.
If you’re running traditional EC2 workloads, this strategy is a great step towards reliable DevOps automation.
AWS architecture visual
I’ve been following your blog for quite some time now, and I’m continually impressed by the quality of your content. Your ability to blend information with entertainment is truly commendable.
Thank you so much, Caesar! I truly appreciate your kind words and support. It motivates me to keep sharing more practical content around AWS and DevOps. Stay tuned — a lot more is coming!
I do trust all the ideas youve presented in your post They are really convincing and will definitely work Nonetheless the posts are too short for newbies May just you please lengthen them a bit from next time Thank you for the post
Just wish to say your article is as surprising The clearness in your post is just cool and i could assume youre an expert on this subject Fine with your permission allow me to grab your RSS feed to keep updated with forthcoming post Thanks a million and please keep up the enjoyable work
My brother suggested I might like this blog He was totally right This post actually made my day You can not imagine simply how much time I had spent for this info Thanks