Amazon Web Services
Compute
- AWS EC2
- EC2 Instance Types
- EC2 Pricing Models
- EC2 Auto Scaling
- Elastic Load Balancing-ELB
- AWS Lambda β Serverless Computing
- Amazon Lightsail
- AWS Elastic Beanstalk
- AWS Fargate
- Amazon ECS (Elastic Container Service)
- Amazon EKS (Elastic Kubernetes Service)
DynamoDB
- DynamoDB Global Table vs Regular DynamoDB Table
- DynamoDB Streams
- Athena query data to DynamoDB
- Athena Query Results with DynamoDB
- PySpark DataFrame to DynamoDB
Redshift
Lambda
Glue
Lambda
Storage
- S3 vs. EBS vs. EFS
- Amazon S3 (Simple Storage Service)
- Amazon S3 Storage Classes
- Amazon EBS (Elastic Block Store)
- Amazon EFS (Elastic File System)
- AWS Storage Gateway
- AWS Snowball
- Amazon FSx
- AWS Backup
Security
π° 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:
- On-Demand Instances β pay as you go.
- Reserved Instances β commit for 1β3 years, save up to 72%.
- Spot Instances β bid for unused capacity, up to 90% cheaper.
- 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)
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 instanceec2.start_instances(InstanceIds=['i-0123456789abcdef0'])
# Stop instanceec2.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)
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)
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)
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
- Cost Optimization β Choosing the right model can save 50β90%.
- Business Planning β Predictable workloads benefit from reservations.
- Scalability β Spot instances allow massive scale at low cost.
- Certifications & Interviews β AWS Solutions Architect exams always test pricing models.
- 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?