EC2: instances & pricing

AMIs, instance types, On-Demand/Reserved/Spot.

Beginner30 min · lesson 4 of 15

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.

the EC2 building blocks
# 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.

EC2 pricing models
commitment
Savings Plans / Reserved
steady baseline, big discount
flexible
On-Demand
pay-as-you-go, spiky/short-lived
Spot
up to 90% off, interruptible only
Commit for the predictable base, On-Demand for variability, Spot for fault-tolerant bulk. Blending them is the cost-optimal approach.
Spot is not for uninterruptible workloads
Spot Instances can be reclaimed with only a two-minute warning, so running a stateful primary database or a job that cannot tolerate interruption on Spot risks data loss and outages. Use Spot for fault-tolerant, stateless, or checkpointed workloads, and On-Demand or committed capacity for anything that must not be interrupted.