AMIs & Instance Types

An AMI is the template that boots your instance; the instance type decides how much CPU and memory it gets.

Two choices define what an EC2 instance is: its image and its size.

Amazon Machine Images (AMIs)

An AMI is a template containing an operating system and optionally pre-installed software. You can use AWS-provided AMIs (Amazon Linux, Ubuntu, Windows), Marketplace AMIs, or build your own golden image so new instances start ready to go.

Instance types

The instance type sets the hardware. Families are grouped by purpose:

FamilyOptimized forExample
T / MGeneral purposet3.micro, m6i.large
CComputec6i.xlarge
R / XMemoryr6i.large
P / GGPU / MLg5.xlarge

The name encodes family, generation and size: t3.micro is family T, generation 3, size micro.

Example

Example · bash
# Find the latest Amazon Linux 2023 AMI ID via SSM Parameter Store
aws ssm get-parameters \
  --names /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-x86_64 \
  --query "Parameters[0].Value" --output text

# List available instance types that have 2 vCPUs
aws ec2 describe-instance-types \
  --filters "Name=vcpu-info.default-vcpus,Values=2" \
  --query "InstanceTypes[].InstanceType"

When to use it

  • A DevOps team creates a custom AMI with all dependencies pre-installed so new Auto Scaling instances boot ready to serve traffic in under a minute.
  • An ML team selects a p3.2xlarge instance type for its NVIDIA V100 GPU when fine-tuning a language model.
  • A startup uses t3.nano instances for low-traffic staging environments and c6i.large for CPU-intensive production workloads.

More examples

Find Latest Amazon Linux 2 AMI

Queries AWS for the most recent Amazon Linux 2 AMI ID in your region, useful for always launching up-to-date images.

Example · bash
aws ec2 describe-images \
  --owners amazon \
  --filters 'Name=name,Values=amzn2-ami-hvm-*-x86_64-gp2' \
  --query 'sort_by(Images,&CreationDate)[-1].ImageId' \
  --output text

Create Custom AMI from Instance

Creates a reusable AMI snapshot from a configured instance so future launches start with all software already installed.

Example · bash
aws ec2 create-image \
  --instance-id i-0123456789abcdef0 \
  --name "my-app-v1.2-$(date +%Y%m%d)" \
  --description "App server with deps pre-installed" \
  --no-reboot

Compare Instance Type Specs

Compares CPU and memory specs of multiple instance types side-by-side to help choose the right size for a workload.

Example · bash
aws ec2 describe-instance-types \
  --instance-types t3.micro t3.small t3.medium \
  --query 'InstanceTypes[].{Type:InstanceType,vCPU:VCpuInfo.DefaultVCpus,RAM:MemoryInfo.SizeInMiB}' \
  --output table

Discussion

  • Be the first to comment on this lesson.