Skip to Content

Immutable infrastructure

Immutable infrastructure on AWS - replacing resources instead of patching them in place, with golden AMIs from EC2 Image Builder, infrastructure as code, blue/green and canary deployments, and drift detection.

Not in the course slides

Immutable infrastructure is on the exam guide's list of concepts (Domain 2) but not in the course slides. This page is written from the AWS documentation (Well-Architected best practice REL08-BP04).

What it is

Immutable infrastructure means no updates, security patches or configuration changes happen in place on production resources. When something must change, the team builds new resources with the change, tests them, moves traffic to them and throws the old ones away.

  • Mutable (the old way): SSH into the servers and patch them. Over months each server drifts a little from the others, and nobody knows exactly what's on them.
  • Immutable: servers are like cattle, not pets. Version 2 is a new image on new instances; version 1 is deleted.

Why it helps

  • Consistency: every environment runs the same tested image, so testing is simpler.
  • No configuration drift: resources are always in a known, version-controlled state.
  • Atomic deployments: a deployment either completes or nothing changes.
  • Fast, safe rollback: the previous version still exists; switch back to it.
  • Better security: with no in-place changes, SSH and remote access can be turned off entirely.

How to do it on AWS

Immutable infrastructure with a blue/green switch: EC2 Image Builder bakes and tests AMI v2, which goes into a new launch template for a new green Auto Scaling group; the load balancer shifts traffic from the blue group on AMI v1 to the green group, and the blue group is drained and terminated instead of being patched in place Immutable infrastructure with a blue/green switch: EC2 Image Builder bakes and tests AMI v2, which goes into a new launch template for a new green Auto Scaling group; the load balancer shifts traffic from the blue group on AMI v1 to the green group, and the blue group is drained and terminated instead of being patched in place

Build new, switch traffic, delete old.
  • Prebake images: EC2 Image Builder pipelines build, patch, test and distribute golden AMIs (and container images) on a schedule.
  • Infrastructure as code: CloudFormation (or the CDK) declares every resource, stored in source control. A change is a new template version, not a console click.
  • Deployment patterns:
    • Blue/green: a full new fleet (green) runs beside the old one (blue); switch traffic all at once or gradually (ALB weighted target groups, Route 53 weighted records), then delete blue. CodeDeploy and Elastic Beanstalk support it.
    • Canary: send a small share of users to the new version, watch errors, then roll out further or roll back. CodeDeploy supports canary configurations (including for Lambda and ECS).
    • Auto Scaling instance refresh: replace instances in an ASG with ones from a new launch template, in batches.
  • Detect drift: CloudFormation drift detection and AWS Config rules find anything changed by hand.
  • Disallow in-place changes: IAM policies (and SCPs) that stop people modifying running production resources.

Containers and Lambda are immutable by design: each deployment is a new image or a new function version.

Real-world examples

  • A bank rebuilds its golden AMI with EC2 Image Builder every week, runs its security tests in the pipeline, and rolls the new AMI out with an ASG instance refresh. Nobody has SSH access to production.

Exam tips

  • "Avoid configuration drift, replace instead of patching" → immutable infrastructure: new AMI + new instances.
  • "Automate building and patching AMIs" → EC2 Image Builder.
  • "Deploy with near-zero downtime and instant rollback" → blue/green (CodeDeploy, Elastic Beanstalk, Route 53 weighted).
  • "Test a new version on a small share of traffic first" → canary deployment.
  • "Find resources changed outside CloudFormation" → drift detection.

Common traps

  • "Use Systems Manager Patch Manager on production servers" when the question asks for immutable infrastructure. Patching in place is mutable; patch the image and replace the instances.
  • "Blue/green halves the cost." For a while both fleets run; it costs more during the switch.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt