Difficulty: Beginner
What are the EC2 pricing models, how do instance types differ, and how would you pick the right combination for a workload?
EC2 offers four main ways to pay: On-Demand (pay per second, no commitment), Savings Plans or Reserved Instances (commit to 1 or 3 years for a large discount), Spot Instances (spare capacity at up to 90% off that AWS can reclaim with a 2-minute warning), and Dedicated Hosts/Instances (hardware not shared with other customers, for licensing or compliance). Most production setups mix them: commitments for the steady baseline, On-Demand for peaks, and Spot for interruptible work.
| Model | Discount vs On-Demand | Commitment | Best for |
|---|---|---|---|
| On-Demand | None | None | Spiky, unknown or short-lived workloads |
| Compute Savings Plan | Up to about 66% | $/hour for 1 or 3 years | Steady usage across EC2, Fargate and Lambda, any family or Region |
| EC2 Instance Savings Plan / Standard RI | Up to about 72% | 1 or 3 years, fixed family and Region | Very predictable fleets |
| Spot | Up to 90% | None, but can be interrupted | Batch jobs, CI runners, stateless workers, ML training with checkpoints |
| Dedicated Host | Varies | Optional | Per-socket or per-core software licences, strict isolation |
Linux On-Demand instances are billed per second with a 60-second minimum. Savings Plans are now the default recommendation over Reserved Instances because they apply automatically and are more flexible. On-Demand Capacity Reservations are separate: they guarantee capacity in an AZ but give no discount on their own.
Take m7g.xlarge:
m is the family: general purpose.7 is the generation; newer is usually cheaper per unit of performance.g is an attribute: AWS Graviton (ARM). Others include i (Intel), a (AMD), d (local NVMe), n (enhanced networking).xlarge is the size; each step up roughly doubles vCPU and memory.Main families: T (burstable, CPU credits), M (balanced), C (compute heavy), R/X (memory heavy, caches and in-memory databases), I/D (local storage), P/G/Inf/Trn (GPUs and AI accelerators).
price-capacity-optimized allocation strategy to reduce interruptions.unlimited mode avoids throttling but bills extra credits.aws ec2 describe-spot-price-history \
--region ap-south-1 \
--instance-types m7g.large \
--product-descriptions "Linux/UNIX" \
--start-time $(date -u +%Y-%m-%dT%H:%M:%S) \
--query "SpotPriceHistory[].{AZ:AvailabilityZone,Price:SpotPrice}" \
--output table
Spot prices differ by AZ and change slowly based on supply and demand; compare them with the On-Demand price before deciding.
{
"LaunchTemplate": {
"LaunchTemplateSpecification": { "LaunchTemplateName": "worker-lt", "Version": "$Latest" },
"Overrides": [
{ "InstanceType": "m7g.large" },
{ "InstanceType": "m6g.large" },
{ "InstanceType": "c7g.large" }
]
},
"InstancesDistribution": {
"OnDemandBaseCapacity": 2,
"OnDemandPercentageAboveBaseCapacity": 20,
"SpotAllocationStrategy": "price-capacity-optimized"
}
}
This MixedInstancesPolicy keeps 2 On-Demand instances always, then fills 80% of extra capacity with Spot across three instance types to lower interruption risk.
On-Demand, Savings Plans, Spot Instances, Reserved Instances, Instance families, Graviton