DevOpsContainers

Implementing Zero Downtime Blue/Green Deployments in ECS

NT

Naveen Teja

2/27/2026

Implementing Zero Downtime Blue/Green Deployments in ECS

Deploying containerized microservices into production carries inherent risks. A standard rolling update can cause dropped requests or temporary instability. Blue/Green deployments mitigate this by running two identical production environments simultaneously, allowing you to shift traffic safely and rollback instantly if metrics degrade.

In the AWS ecosystem, this is achieved by integrating Elastic Container Service (ECS) with AWS CodeDeploy. CodeDeploy provisions a 'Green' replacement task set, attaches it to a secondary Target Group on your Application Load Balancer, and runs pre-traffic test hooks. Once the new containers are validated, traffic is safely shifted over.

To configure this infrastructure, your ECS service must use the `CODE_DEPLOY` deployment controller rather than the standard ECS rolling update. You also need to configure a CodeDeploy application and deployment group that references your ALB listeners and target groups. Here is the Terraform snippet to enable the CodeDeploy controller on ECS.

ecs-blue-green.tf
resource "aws_ecs_service" "app" {
  name            = "microservice-prod"
  cluster         = aws_ecs_cluster.main.id
  task_definition = aws_ecs_task_definition.app.arn
  launch_type     = "FARGATE"

  deployment_controller {
    type = "CODE_DEPLOY"
  }

  load_balancer {
    target_group_arn = aws_lb_target_group.blue.arn
    container_name   = "app-container"
    container_port   = 8080
  }
}