Baking a Golden AMI
Pre-build a machine image with your app and dependencies so new instances launch ready to serve.
Installing everything at boot with user data works, but it is slow and can fail if a package server is down. A golden AMI is a snapshot of a fully-configured instance β OS, runtime, dependencies, and app all baked in. New instances launched from it are ready in seconds.
The immutable pattern
- Launch a base instance and configure it.
- Create an AMI from it.
- Launch all production instances from that AMI.
- To deploy a new version, bake a new AMI and roll instances over.
This is immutable infrastructure: you never patch a running server, you replace it. Tools like Packer automate the baking step.
Example
# Create a reusable AMI from a configured instance
aws ec2 create-image \
--instance-id i-0123456789abcdef0 \
--name "myapp-2026-07-15" \
--description "MyApp with node 20 + deps baked in" \
--no-reboot
# Later, launch new instances from that AMI id (ami-xxxx)When to use it
- A team bakes a golden AMI with Node.js and the app installed so auto-scaling group instances launch pre-configured without running a bootstrap script.
- An ops engineer creates an AMI from a hardened base instance so security patches are baked in and new machines inherit the baseline.
- A company builds a new AMI on every release and updates the launch template, making rollbacks as simple as pointing back to the previous AMI ID.
More examples
Create AMI from a running instance
Captures a running instance as a new AMI snapshot, tagging it with a timestamp for easy identification.
AMI_ID=$(aws ec2 create-image \
--instance-id i-0abc12345 \
--name "myapp-$(date +%Y%m%d-%H%M)" \
--no-reboot \
--query 'ImageId' \
--output text)
echo "New AMI: $AMI_ID"Wait for AMI to become available
Pauses the script until AWS finishes building the AMI so subsequent steps can safely reference it.
aws ec2 wait image-available --image-ids $AMI_ID
echo "AMI $AMI_ID is ready"Update launch template to new AMI
Creates a new launch template version pointing to the freshly baked AMI so new auto-scaling instances use it.
aws ec2 create-launch-template-version \
--launch-template-id lt-0abc123 \
--source-version '$Latest' \
--launch-template-data "{\"ImageId\":\"$AMI_ID\"}" \
--version-description "Release $(date +%Y%m%d)"
Discussion