Deep Dive into AWS EC2 Spot Instances & Spot Fleets
What Are EC2 Spot Instances?
EC2 Spot Instances allow users to purchase spare AWS compute capacity at discounts of up to 90% compared to On-Demand pricing.
- How Spot Pricing Works:
- You define a maximum spot price you are willing to pay.
- If the current spot price is below your max price, you get the instance.
- If the spot price exceeds your max price, your instance is stopped or terminated (depending on your settings).
- AWS provides a 2-minute grace period before termination.
Two Termination Strategies for Spot Instances:
- Stop & Resume:
- The instance is stopped and can be restarted when the spot price drops again.
- Ideal for stateful workloads that need to resume processing later.
- Terminate & Relaunch:
- The instance is terminated, and a new instance will need to be launched.
- Suitable for stateless workloads that can start fresh.
Using Spot Blocks for Guaranteed Uptime
If you don't want your spot instance to be interrupted, use a Spot Block:
- Ensures the instance runs without interruption for 1 to 6 hours.
- Rare cases exist where AWS may reclaim the instance, but it's uncommon.
When to Use Spot Instances?
Spot instances are best suited for:
✅ Batch jobs
✅ Data analysis
✅ Fault-tolerant workloads (resilient to interruptions)
They are not recommended for:
❌ Critical applications
❌ Databases or workloads needing persistent storage