πŸ’° AWS EC2 Pricing Models Explained: On-Demand, Reserved, Spot Instances & Savings Plans

Amazon EC2 (Elastic Compute Cloud) is one of the most widely used AWS services. But when running workloads on EC2, pricing can make or break your cloud strategy.

AWS offers multiple pricing models to fit different workloads and budgets:

  1. On-Demand Instances – pay as you go.
  2. Reserved Instances – commit for 1–3 years, save up to 72%.
  3. Spot Instances – bid for unused capacity, up to 90% cheaper.
  4. Savings Plans – flexible commitment across compute services.

Choosing the right pricing model is critical for:

  • Cost savings
  • Performance reliability
  • Scalability planning

Let’s dive into each one with real-world examples and code demonstrations.


πŸ”‘ 1. On-Demand Instances

πŸ“Œ What Are They?

  • Pay by the second (Linux) or hour (Windows).
  • No upfront commitment.
  • Flexible but most expensive option.

βœ… When to Use

  • Short-term workloads.
  • Development/testing environments.
  • Unpredictable usage patterns.

πŸ–₯️ Example Programs for On-Demand Instances

Example 1: Launch On-Demand Instance (AWS CLI)

Terminal window
aws ec2 run-instances \
--image-id ami-1234567890abcdef0 \
--count 1 \
--instance-type t3.micro \
--key-name MyKeyPair \
--security-groups my-sg

Example 2: Python Script to Start/Stop On-Demand Instance

import boto3
ec2 = boto3.client('ec2')
# Start instance
ec2.start_instances(InstanceIds=['i-0123456789abcdef0'])
# Stop instance
ec2.stop_instances(InstanceIds=['i-0123456789abcdef0'])

Example 3: Terraform Script for On-Demand Instance

resource "aws_instance" "on_demand" {
ami = "ami-12345678"
instance_type = "t3.micro"
tags = {
Name = "on-demand-instance"
}
}


πŸ”‘ 2. Reserved Instances (RIs)

πŸ“Œ What Are They?

  • Commit to 1-year or 3-year usage.
  • Save up to 72% compared to On-Demand.
  • Options: Standard RI (maximum savings) and Convertible RI (flexible type change).

βœ… When to Use

  • Steady-state workloads (databases, web servers).
  • Predictable usage patterns.
  • Long-term applications.

πŸ–₯️ Example Programs for Reserved Instances

Example 1: Purchase Reserved Instance (CLI)

Terminal window
aws ec2 purchase-reserved-instances-offering \
--reserved-instances-offering-id abc12345 \
--instance-count 1

Example 2: Python Example to Describe Reserved Instances

import boto3
ec2 = boto3.client('ec2')
response = ec2.describe_reserved_instances()
for ri in response['ReservedInstances']:
print("ID:", ri['ReservedInstancesId'], "State:", ri['State'])

Example 3: CloudFormation for Reserved Instance Purchase

Resources:
MyReservedInstance:
Type: AWS::EC2::Instance
Properties:
InstanceType: m5.large
ImageId: ami-0abcdef1234567890
Tenancy: default


πŸ”‘ 3. Spot Instances

πŸ“Œ What Are They?

  • Use unused EC2 capacity at up to 90% discount.
  • Instances can be interrupted with 2-minute warning.
  • Best for fault-tolerant workloads.

βœ… When to Use

  • Batch processing.
  • Data analytics.
  • Machine learning training.
  • CI/CD pipelines.

πŸ–₯️ Example Programs for Spot Instances

Example 1: Request Spot Instance (CLI)

Terminal window
aws ec2 request-spot-instances \
--spot-price "0.05" \
--instance-count 1 \
--type "one-time" \
--launch-specification file://specification.json

Example 2: Python Example for Spot Requests

import boto3
ec2 = boto3.client('ec2')
response = ec2.request_spot_instances(
SpotPrice="0.05",
InstanceCount=1,
LaunchSpecification={
'ImageId': 'ami-0abcdef1234567890',
'InstanceType': 'c5.large'
}
)
print(response['SpotInstanceRequests'])

Example 3: Specification File for Spot Instance

{
"ImageId": "ami-0abcdef1234567890",
"InstanceType": "m5.large",
"KeyName": "MyKeyPair",
"SecurityGroups": ["spot-sg"]
}


πŸ”‘ 4. Savings Plans

πŸ“Œ What Are They?

  • Flexible pricing model launched in 2019.
  • Commit to $/hour spend for 1–3 years.
  • Applies across EC2, Fargate, and Lambda.
  • Two types: Compute Savings Plan (max flexibility) and EC2 Instance Savings Plan (specific family/region).

βœ… When to Use

  • Mixed workloads across services.
  • Businesses moving toward serverless or containers.
  • Organizations wanting savings with flexibility.

πŸ–₯️ Example Programs for Savings Plans

Example 1: View Savings Plans (CLI)

Terminal window
aws savingsplans describe-savings-plans

Example 2: Python Example to Describe Savings Plans

import boto3
client = boto3.client('savingsplans')
plans = client.describe_savings_plans()
for plan in plans['savingsPlans']:
print("Plan ID:", plan['savingsPlanId'], "State:", plan['state'])

Example 3: Cost Explorer Example to Track Savings

import boto3
ce = boto3.client('ce')
response = ce.get_savings_plans_utilization(TimePeriod={'Start': '2025-08-01','End': '2025-08-27'})
print(response['SavingsPlansUtilizationsByTime'])


🧠 How to Remember for Interview & Exam

  • On-Demand β†’ Pay as you go. (Think: renting a car by the hour.)
  • Reserved β†’ Commit & save. (Think: annual train pass.)
  • Spot β†’ Cheapest but interruptible. (Think: last-minute flight deals.)
  • Savings Plans β†’ Commit spend, flexible usage. (Think: Netflix subscription – fixed monthly, use anytime.)

πŸ‘‰ Trick: Remember acronym ORSS (On-Demand, Reserved, Spot, Savings).


🎯 Why It’s Important to Learn Pricing Models

  1. Cost Optimization – Choosing the right model can save 50–90%.
  2. Business Planning – Predictable workloads benefit from reservations.
  3. Scalability – Spot instances allow massive scale at low cost.
  4. Certifications & Interviews – AWS Solutions Architect exams always test pricing models.
  5. Real-World Impact – Cost savings directly affect business profit margins.

πŸ“Œ Conclusion

AWS EC2 pricing models give you flexibility, savings, and scalability.

  • On-Demand β†’ maximum flexibility, higher cost.
  • Reserved Instances β†’ long-term savings for predictable workloads.
  • Spot Instances β†’ biggest savings but risk of interruption.
  • Savings Plans β†’ best of both worlds, flexible and cost-effective.

Mastering these options is critical for cloud architects, developers, and anyone preparing for AWS certifications.


✨ Pro Tip for Exams: Always ask β†’ Is workload steady, flexible, or fault-tolerant? That tells you which pricing model fits best.


Would you like me to also add a comparison cheat sheet table (On-Demand vs Reserved vs Spot vs Savings Plans) for quick revision before interviews/exams?