AMI
Amazon Machine Image
A template for AWS EC2 instances. Includes the OS and software configuration. Fast server cloning.
Amazon Machine Image
A template for AWS EC2 instances. Includes the OS and software configuration. Fast server cloning.
AMI (Amazon Machine Image) is a template that contains all the information needed to launch an AWS EC2 instance. The operating system (Amazon Linux, Ubuntu, Windows Server, etc.), application server, runtime, application code, system settings, and more are packaged into a single image, so servers with an identical environment can be cloned instantly.
AMI was introduced in 2006 together with the launch of the EC2 service. In the physical server era, building a new server took several hours for OS installation, package installation, configuration, and so on, but with an AMI, servers with a completely identical environment can be cloned endlessly within minutes. This is the foundation of "Immutable Infrastructure," a core concept of cloud-native infrastructure.
AMI is based on EBS snapshots. It includes snapshots of the root volume and additional volumes, launch permissions (which AWS accounts can use this AMI), and block device mapping (definition of the volumes to attach when an instance is launched). It uses HVM (Hardware Virtual Machine) virtualization and supports x86_64 and ARM (Graviton) architectures.
In practice, an AMI is specified in the Launch Template of Auto Scaling and is used to automatically scale out/in identical servers. Through a Golden AMI strategy, you can create a base image with security patches and basic settings applied, and operate standardized servers across the entire organization.
# 현재 리전의 최신 Amazon Linux 2023 AMI 찾기
aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=al2023-ami-2023*-x86_64" \
"Name=state,Values=available" \
--query 'Images | sort_by(@, &CreationDate) | [-1].ImageId' \
--output text
# 실행 중인 인스턴스에서 AMI 생성
aws ec2 create-image \
--instance-id i-1234567890abcdef0 \
--name "my-app-v1.2.3-$(date +%Y%m%d)" \
--description "Production web server with Node.js 20" \
--no-reboot
# AMI 생성 상태 확인
aws ec2 describe-images \
--image-ids ami-0123456789abcdef0 \
--query 'Images[0].State'
# AMI로 인스턴스 시작
aws ec2 run-instances \
--image-id ami-0123456789abcdef0 \
--instance-type t3.medium \
--key-name my-keypair \
--security-group-ids sg-12345678 \
--subnet-id subnet-12345678 \
--count 1
# 다른 리전으로 AMI 복사
aws ec2 copy-image \
--source-region us-east-1 \
--source-image-id ami-0123456789abcdef0 \
--name "my-app-v1.2.3-ap-northeast-2" \
--region ap-northeast-2
# 오래된 AMI 삭제 (deregister + snapshot 삭제)
aws ec2 deregister-image --image-id ami-old123456
aws ec2 delete-snapshot --snapshot-id snap-old123456
"This deployment will go out with a new AMI. ami-0abc123, built with Packer, has finished testing, and once we update the Launch Template version and run an instance refresh in the ASG, it will roll out with zero downtime. If something goes wrong, we can roll back to the previous AMI."
"We applied a Golden AMI strategy: we built a base AMI with security patches, the CloudWatch Agent, and the SSM Agent pre-installed, and each team operated by adding only their application on top of this base. We integrated Packer with the CI/CD pipeline to automatically build a new security-patched AMI every month."
"When a new instance doesn't launch in Auto Scaling, it's because the AMI was deleted or is in a different region. Check whether the AMI ID specified in the Launch Template exists in the current region, and if it doesn't, update it to a new AMI or copy it over from another region."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Do not include API keys, passwords, SSH keys, etc. in an AMI. If an AMI is shared or leaked, it leads to a security incident. Retrieve secrets at runtime from Secrets Manager or Parameter Store.
If you do not delete the EBS snapshots associated with old AMIs, storage costs continue to accrue. Set up an AMI Lifecycle Policy or regularly clean up unused AMIs. In particular, if you build frequently with Packer, AMIs accumulate quickly.
Secure flexibility with a combination of a base AMI and User Data. If the base AMI contains only the OS and common packages, and application deployment is handled through User Data or CodeDeploy, you can reduce how often you build AMIs. A Graviton (ARM) AMI offers up to 40% better price-performance than x86, so consider it.