Sub topic 3
Choosing an AMI
This chapter assumes you know basic Linux commands, can read CIDR blocks, and understand that an EC2 instance is a virtual server in a Region. You do not need to have launched an instance yet.
What an AMI contains
An Amazon Machine Image (AMI) is the template EC2 uses to create an instance. It holds three things:
- A root volume snapshot or template, which contains the operating system and any preinstalled software.
- Launch permissions, which control which AWS accounts can use the image.
- A block device mapping, which lists the volumes to attach at launch.
Every instance starts as a copy of one AMI. Changes you make inside the running instance do not alter the AMI.
Where AMIs come from
| Source | Example | When to use it |
|---|---|---|
| AWS-provided | Amazon Linux 2023, Ubuntu, Windows Server | A clean, maintained starting point |
| AWS Marketplace | Vendor images with licensed software | You want a prebuilt product and accept its cost |
| Community | Images shared publicly by other accounts | Rarely. You cannot easily verify their contents |
| Your own | An image you create from a configured instance | You want repeatable launches with your software baked in |
Prefer AWS-provided or well-known vendor images. Treat community AMIs as untrusted unless you can verify the publisher.
Properties that affect your choice
- Region. An AMI exists in one Region. An AMI ID in
us-east-1does not work ineu-west-1. To use an image elsewhere, copy it to the target Region, which produces a new AMI ID. - Architecture. The image must match the instance type:
x86_64for Intel and AMD,arm64for Graviton. A mismatch causes the launch to fail. - Root device type. Most current AMIs are EBS-backed, so the root volume persists across stop and start. Instance store-backed images are rare and lose their root data when stopped.
- Virtualization and boot mode. Current AMIs use hardware virtual machine (HVM) and usually support UEFI or legacy BIOS boot. Use the AWS defaults unless you have a specific need.
Finding the current AMI without hard-coding an ID
AMI IDs change whenever AWS publishes a patched image. Instead of copying an ID from a web page, read it from a public Systems Manager (SSM) parameter:
AMI_ID=$(aws ssm get-parameter \
--name /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
--query Parameter.Value --output text)
echo "$AMI_ID"The parameter name contains x86_64. For Graviton instance types, use the matching arm64 parameter. Run the command in the Region where you plan to launch, because the returned ID is specific to that Region.
You will pass $AMI_ID to run-instances in a later chapter.
Common errors
InvalidAMIID.NotFound. The ID does not exist in the Region your CLI is using. Check your configured Region and the image's source Region.- Architecture mismatch. An
arm64AMI with at3instance type (x86) fails. Pick a type from a matching family. - Stale hard-coded IDs. Old images miss security patches. Resolve the ID at launch time, or rebuild your custom AMI regularly.
Exercise
You copied an AMI ID from a colleague who works in us-east-1, but your CLI is set to eu-west-1 and the launch returns InvalidAMIID.NotFound. What are two ways to fix it?
Show answer
Either copy the AMI to eu-west-1 (which creates a new AMI ID there) or look up an equivalent image in eu-west-1, for example by reading the public SSM parameter while your CLI is set to that Region. AMI IDs are Region-specific.