iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

EC2 Instance Types

EC2 instance types are not interchangeable. The family letter encodes the dominant workload (M=general, C=compute, R=memory, T=burst, G=GPU, I=storage), the number is the generation, and the suffix tags the CPU vendor (a=AMD, g=Graviton/ARM, blank=Intel). Picking the wrong family is the single biggest source of overspend.

Choose, launch, and resize instance types

EXAMPLE
# 1) Map workload to family (rules of thumb)
#   - General-purpose web/API, Rails/Django/Laravel:    m7g.large (Graviton)
#   - Encoding, simulation, busy CI runners:            c7i.4xlarge
#   - In-memory DBs, large caches, JVM heaps:           r7g.2xlarge
#   - Dev boxes, low-traffic prod:                      t4g.small (bursts)
#   - GPU inference:                                    g6.xlarge (L4 GPU)
#   - Local NVMe-heavy DBs:                             i4i.large

# 2) Compare price and specs in one shot
aws ec2 describe-instance-types \
  --instance-types m7g.large c7i.large r7g.large t4g.small \
  --query 'InstanceTypes[].[InstanceType,VCpuInfo.DefaultVCpus,MemoryInfo.SizeInMiB,ProcessorInfo.SupportedArchitectures[0]]' \
  --output table

# 3) Launch one with sensible defaults
aws ec2 run-instances \
  --image-id resolve:ssm:/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64 \
  --instance-type m7g.large \
  --key-name dev-keypair \
  --security-group-ids sg-0abc1234 \
  --subnet-id subnet-0def5678 \
  --metadata-options 'HttpTokens=required,HttpEndpoint=enabled' \
  --block-device-mappings '[{"DeviceName":"/dev/xvda","Ebs":{"VolumeSize":30,"VolumeType":"gp3","Encrypted":true}}]' \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-1},{Key=env,Value=prod}]'

# 4) Resize an existing instance (must stop it first)
aws ec2 stop-instances --instance-ids i-0abc1234
aws ec2 wait instance-stopped --instance-ids i-0abc1234
aws ec2 modify-instance-attribute --instance-id i-0abc1234 \
  --instance-type '{"Value":"m7g.xlarge"}'
aws ec2 start-instances --instance-ids i-0abc1234

# 5) When in doubt, ask Compute Optimizer (free, runs on CloudWatch metrics)
aws compute-optimizer get-ec2-instance-recommendations \
  --query 'instanceRecommendations[].{Id:instanceArn,Current:currentInstanceType,Top:recommendationOptions[0].instanceType,Savings:recommendationOptions[0].savingsOpportunity.savingsOpportunityPercentage}' \
  --output table

Why it matters

Graviton (g-suffix) is roughly 20% cheaper for the same throughput on most web/API and JVM workloads — and it has been stable for years. Default new fleets to Graviton; only fall back to Intel/AMD when you hit a native dependency that has not shipped an arm64 build.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
# t4g = burstable. m7i = balanced. c7i = compute. r7i = memory. g5 = GPU.
Try it Yourself »

Discussion

Loading…