Marcio Cunha

Zero downtime deploy on AWS: how to configure Blue-Green

Learn how to execute seamless, continuous deployments on AWS using load balancers and auto scaling groups.

Marcio Cunha•4 min
Also available in:EspañolPortuguês
Summary
  • The blue-green strategy eliminates downtime by switching traffic between two identical infrastructure environments.
  • The load balancer acts as the maestro directing users to the correct environment seamlessly.
  • Auto scaling groups ensure new instances are ready to handle production traffic without manual intervention.
  • Instant rollbacks protect the business if a critical bug slips through to the production environment.
  • Rigorous testing in the inactive environment drastically reduces unpleasant surprises after the switch.

What is the blue-green model and why it eliminates downtime

When updating a production system, the biggest fear is seeing an error screen pop up for the end user during the release process. In practice, this means the application went offline while files were replaced or services restarted. To solve this problem, the approach known as blue-green keeps two identical server environments running in parallel. While one environment, called blue, handles all current customer traffic, the other environment, called green, receives the new software version in complete isolation and without any rush.

This physical separation ensures that any code failure happens far away from the eyes of everyday users. If something goes wrong during installation, the business impact is zero because the old environment remains untouched and ready to save the operation. Furthermore, this heavy safety net accelerates technology team deliveries, as the fear of breaking the application decreases drastically. Before learning how to build this structure in AWS, it is worth remembering that keeping pipelines clean avoids unexpected surprises, as we saw when exploring how to solve Docker disk space issues during builds.

How the Application Load Balancer manages traffic shifting

The maestro behind this seamless transition process is the AWS Application Load Balancer. In practice, it works like the reception desk of a large commercial building, directing visitors to the right room without them noticing what is happening behind the scenes. Once the new software version is fully tested and approved in the green environment, engineers change a simple rule in the load balancer. Within seconds, new requests start being sent to the updated servers, while old connections are gracefully drained.

This nearly instant switch eliminates the classic maintenance window that used to happen in the middle of the night. If system monitors identify a sudden spike in errors after the change, the load balancer can point traffic right back to the blue environment with a single click. In modern software engineering, this quick rollback capability separates a stressful operation from a fluid, automated process. Should you need to handle more complex infrastructure failures, it is worth checking out strategies to use Terraform and rollback failed AWS deployments.

The role of auto scaling groups in environment elasticity

Maintaining two complete infrastructures running 24/7 might look like a waste of money at first glance, but auto scaling groups solve this financial dilemma. In practice, these groups automatically adjust the number of active servers based on real user demand. While the green environment is inactive waiting for a new deploy, it can run with the minimum number of instances turned on, drastically cutting operational costs. As soon as the team decides to start an update, the green auto scaling group is warmed up with fully configured virtual machines.

These machines are born with the new code already installed via pre-baked system images, ensuring the environment scales up exactly as planned. Besides saving financial resources, this automation eliminates human errors caused by typing manual commands on production servers. Maintaining system integrity also involves ensuring security processes and certificates are always up to date, a topic we cover in detail when showing how to automate SSL certificate renewals with Vault.

Step-by-step configuration for the blue and green architecture

To bring this strategy to life using infrastructure as code, we need to define the core building blocks that make up the scenario. The configuration below demonstrates how to structure basic resources to route traffic safely between two distinct targets.

resource 'aws_lb_target_group' 'blue' {name = 'target-blue'port = 80protocol = 'HTTP'target_type = 'instance'vpc_id = var.vpc_id}resource 'aws_lb_listener_rule' 'routing' {listener_arn = aws_lb_listener.front.arnpriority = 100action {type = 'forward'target_group_arn = aws_lb_target_group.blue.arn}condition {path_pattern {values = ['/app/*']}}}

The code snippet above illustrates how the load balancer initially routes traffic to the blue target group, establishing the starting point of our application. During the update process, the automation script creates the green group and changes the target ARN once health checks complete successfully. This level of programmatic control ensures no machine enters production without proving it works perfectly.

Final thoughts on resilience and cloud operations

Adopting the blue-green deployment model with load balancers and auto scaling groups transforms a company's engineering culture. The fear of updating systems during business hours disappears, giving way to continuous, safe deliveries that are completely transparent to end users. Although it requires careful upfront planning and a modest investment in duplicated infrastructure, the return on investment shows up the first time a critical bug is avoided or reverted in seconds.

Ultimately, cloud service stability does not depend solely on writing flawless code, but on building resilient networks that absorb failures without stress. By combining intelligent automation, constant monitoring, and well-rehearsed traffic switching routines, your team achieves the operational maturity needed to grow with total peace of mind.