On-demand vs Reserved vs Spot Instances in AWS: Key Differences and Use Cases
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.
| Factor | On-demand Instance | Reserved Instance | Spot Instance |
|---|---|---|---|
| Pricing Model | Pay per use, no commitment | Pay upfront or monthly for 1-3 years | Use spare capacity at low prices |
| Cost | Highest | Lower than On-demand | Lowest |
| Availability | Always available | Capacity reserved | Available when spare capacity exists |
| Use Case | Short-term, unpredictable workloads | Steady-state or predictable workloads | Flexible, fault-tolerant workloads |
| Interruption Risk | None | None | Can be interrupted with 2-minute warning |
| Commitment | None | 1 or 3 years | None |
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
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'])
Spot Instance Equivalent
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'])
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.