0
0
AwsComparisonBeginner · 4 min read

On-demand vs Reserved vs Spot Instances in AWS: Key Differences and Use Cases

In AWS, On-demand instances let you pay for compute capacity by the hour or second with no long-term commitment. Reserved instances offer a discount in exchange for a one- or three-year commitment. Spot instances provide the lowest cost by using spare capacity but can be interrupted by AWS with short notice.
⚖️

Quick Comparison

Here is a quick overview of the main differences between On-demand, Reserved, and Spot instances in AWS.

FactorOn-demand InstanceReserved InstanceSpot Instance
Pricing ModelPay per use, no commitmentPay upfront or monthly for 1-3 yearsUse spare capacity at low prices
CostHighestLower than On-demandLowest
AvailabilityAlways availableCapacity reservedAvailable when spare capacity exists
Use CaseShort-term, unpredictable workloadsSteady-state or predictable workloadsFlexible, fault-tolerant workloads
Interruption RiskNoneNoneCan be interrupted with 2-minute warning
CommitmentNone1 or 3 yearsNone
⚖️

Key Differences

On-demand instances are the most flexible option. You pay only for what you use, with no upfront cost or commitment. This makes them ideal for short-term or unpredictable workloads where you need capacity immediately.

Reserved instances require you to commit to a 1- or 3-year term, either paying upfront or monthly. In return, you get a significant discount compared to On-demand pricing. These are best for steady workloads where you know you will need capacity long-term.

Spot instances let you use AWS's spare capacity at a steep discount, often up to 90% cheaper than On-demand. However, AWS can reclaim these instances with a two-minute warning if it needs the capacity back. Spot instances are great for flexible, fault-tolerant tasks like batch jobs or big data processing that can handle interruptions.

💻

On-demand Instance Example

python
import boto3

# Create EC2 client
ec2 = boto3.client('ec2')

# Launch an On-demand instance
response = ec2.run_instances(
    ImageId='ami-0abcdef1234567890',
    InstanceType='t3.micro',
    MinCount=1,
    MaxCount=1
)

print('Launched On-demand instance:', response['Instances'][0]['InstanceId'])
Output
Launched On-demand instance: i-0123456789abcdef0
↔️

Spot Instance Equivalent

python
import boto3

# Create EC2 client
ec2 = boto3.client('ec2')

# Request a Spot instance
response = ec2.request_spot_instances(
    SpotPrice='0.01',
    InstanceCount=1,
    LaunchSpecification={
        'ImageId': 'ami-0abcdef1234567890',
        'InstanceType': 't3.micro'
    }
)

print('Requested Spot instance:', response['SpotInstanceRequests'][0]['SpotInstanceRequestId'])
Output
Requested Spot instance: sir-0abcd1234efgh5678
🎯

When to Use Which

Choose On-demand instances when you need immediate capacity without long-term commitment or when your workload is unpredictable.

Choose Reserved instances if you have steady, predictable workloads and want to save money by committing to a longer term.

Choose Spot instances for flexible, fault-tolerant workloads that can handle interruptions and where cost savings are a priority.

Key Takeaways

On-demand instances offer flexibility with no commitment but cost the most.
Reserved instances save money for steady workloads by requiring a 1-3 year commitment.
Spot instances provide the lowest cost but can be interrupted anytime.
Use Spot for flexible tasks, Reserved for predictable workloads, and On-demand for short-term needs.