EC2: instances & pricing
AMIs, instance types, On-Demand/Reserved/Spot.
EC2 (Elastic Compute Cloud) is the foundational compute service — resizable virtual machines you control. Choosing instance types, images, and pricing models correctly is core architecture work.
Instances, AMIs, and instance types
An EC2 instance is a virtual server you launch from an Amazon Machine Image (AMI) — a template bundling the OS and any pre-installed software. Baking a golden AMI gives consistent, fast launches. Instances come in families optimized for different workloads: general purpose (balanced), compute optimized (CPU-heavy), memory optimized (in-memory databases, caches), storage optimized (high local I/O), and accelerated (GPU/ML). Choosing the right family and size — right-sizing to actual utilization — is a primary cost and performance decision, and one you revisit as workloads change rather than over-provisioning up front.
# Launch from an AMI, choose a family+size, place in a subnet, attach a role.Instance = AMI (OS + software template)+ instance type (e.g. m6i.large = general purpose, 2 vCPU / 8 GiB)+ subnet (which AZ) + security group (firewall)+ IAM role (instance profile) + EBS volume (root disk)# Families: t/m (general) · c (compute) · r/x (memory) · i/d (storage) · g/p (GPU)
Pricing models
EC2 pricing is a major cost lever. On-Demand is pay-as-you-go with no commitment — ideal for spiky or short-lived workloads. Savings Plans and Reserved Instances give large discounts (up to ~70%) in exchange for a 1- or 3-year commitment to steady usage — use them for your predictable baseline. Spot Instances offer spare capacity at up to ~90% off but can be reclaimed with a two-minute warning — perfect for fault-tolerant, interruptible work like batch processing, CI, and stateless scaling, and wrong for a stateful primary database. The cost-optimal pattern blends them: commit for the baseline, On-Demand for normal variability, Spot for interruptible bulk.