What is an AMI and how is it used when launching EC2 instances?
An Amazon Machine Image is a template holding the operating system, installed software and settings used to start an EC2 instance. You can launch many identical instances from one AMI, and copy it across Regions.
Explain it simply
An AMI is like a pen drive with Windows already installed and your college software preloaded. Plug it into any new laptop and you get the same setup every time. In AWS, you launch an instance from an AMI instead of installing everything by hand.
Example
# Create an image from a running, configured instance
aws ec2 create-image --instance-id i-0abc123 --name "web-v1"
# Launch a new instance from that image
aws ec2 run-instances --image-id ami-0123456789abcdef0 \
--instance-type t3.micro --count 1An AMI contains a root volume snapshot, launch permissions (who may use it) and a block device mapping. Sources are AWS-provided images (Amazon Linux, Ubuntu), the Marketplace, or your own. Custom AMIs speed up Auto Scaling because new instances boot already configured instead of installing software at start-up.
AMIs are Region-specific. To use one elsewhere you copy it, and the copy gets a new AMI ID. You can share an AMI with other AWS accounts or make it public.
What to say in the interview
"An AMI is the template an EC2 instance boots from: OS, software and a root volume snapshot. I bake my own AMIs for consistent, fast Auto Scaling launches. They are Region-scoped, so I copy them to other Regions when needed, and I keep them patched by rebuilding rather than logging in to fix servers."
Common mistakes
- Assuming an AMI ID works in every Region.
- Baking secrets or keys into a shared AMI.