Instance Types & AMIs
Choosing the right instance type and AMI strategy directly impacts cost, performance, and operational complexity. Understanding instance families, pricing models, and AMI lifecycle is essential for production deployments.
Instance Families
# Instance type naming: <family><generation>.<size>
# e.g. t3.medium, m6i.xlarge, c7g.2xlarge, r6a.4xlarge
# General Purpose
# t* — burstable (t2/t3/t4g); cheapest, throttled when CPU credits exhaust; great for low-traffic apps
# m* — balanced CPU/memory (m5/m6i/m7i); the workload baseline
# Compute Optimized
# c* — high CPU-to-memory ratio (c5/c6i/c7g); web serving, batch, gaming servers
# Memory Optimized
# r* — high memory (r5/r6i); databases, in-memory caches
# x* — extreme memory (x1e/x2gd); SAP HANA, in-memory analytics
# z1d — high frequency + NVMe local storage
# Storage Optimized
# i* — NVMe SSD instance storage (i3/i4i); high IOPS databases
# d* — HDD instance storage; data warehouses, Hadoop
# Accelerated Computing
# g* — NVIDIA GPU (g4dn/g5); ML inference, video encoding
# p* — NVIDIA GPU high-end (p3/p4); ML training
# inf* — AWS Inferentia chips; cheapest ML inference
# Processor suffixes
# (none) = Intel Xeon
# a = AMD EPYC
# g = AWS Graviton (ARM) — best price/performance
# i = Intel Ice Lake
# Find instances by attribute using CLI
aws ec2 describe-instance-types \
--filters "Name=memory-info.size-in-mib,Values=8192" \
--query "InstanceTypes[*].{Type:InstanceType,vCPU:VCpuInfo.DefaultVCpus}" \
--output tablePricing Models
# On-Demand — pay per hour/second, no commitment; highest cost
# Use for: unpredictable workloads, dev/test, short-term
# Reserved Instances — 1 or 3 year commitment; up to 72% cheaper than on-demand
# Standard RI: fixed instance type; biggest discount
# Convertible RI: can change instance family/OS; smaller discount (~54%)
# Savings Plans — flexible commitment by $/hr spend; up to 66% savings
# Compute SP: applies to any EC2, Lambda, Fargate — most flexible
# EC2 Instance SP: specific region+family commitment — cheaper than Compute SP
# Spot Instances — unused EC2 capacity; up to 90% cheaper; can be interrupted 2-min notice
# Use for: batch jobs, stateless workers, CI/CD runners, fault-tolerant workloads
# Launch a Spot instance
aws ec2 run-instances \
--instance-type c5.xlarge \
--image-id ami-0c02fb55956c7d316 \
--instance-market-options "MarketType=spot,SpotOptions={MaxPrice=0.05,SpotInstanceType=one-time}"
# Get current spot prices
aws ec2 describe-spot-price-history \
--instance-types c5.xlarge \
--product-descriptions "Linux/UNIX" \
--start-time $(date -u +%Y-%m-%dT%H:%M:%S) \
--query "SpotPriceHistory[*].{AZ:AvailabilityZone,Price:SpotPrice}" \
--output tableAMI Creation & Management
# Create an AMI from a running instance (creates EBS snapshot)
aws ec2 create-image \
--instance-id i-1234567890abcdef0 \
--name "my-app-server-2024-01-15" \
--description "Production app server with v2.3.1" \
--no-reboot # Try not to reboot (may cause filesystem inconsistency)
# Wait until AMI is available
aws ec2 wait image-available --image-ids ami-0abc123def456789
# List your own AMIs
aws ec2 describe-images --owners self \
--query "Images[*].{ID:ImageId,Name:Name,State:State,Date:CreationDate}" \
--output table
# Copy AMI to another region (for DR or multi-region deploy)
aws ec2 copy-image \
--source-region us-east-1 \
--source-image-id ami-0abc123def456789 \
--name "my-app-server-us-west-2" \
--region us-west-2
# Share AMI with another AWS account
aws ec2 modify-image-attribute \
--image-id ami-0abc123def456789 \
--launch-permission "Add=[{UserId=123456789012}]"
# Find latest Amazon Linux 2023 AMI in current region
aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=al2023-ami-*" "Name=architecture,Values=x86_64" \
--query "sort_by(Images, &CreationDate)[-1].ImageId" \
--output text
# Deregister old AMI (first delete snapshots to stop storage charges)
aws ec2 deregister-image --image-id ami-oldimage123
aws ec2 delete-snapshot --snapshot-id snap-0abc123def456789Keep your own version of these notes — editable, searchable, and organised by your stack.
Start free