Spot Instances use spare EC2 capacity auctioned at discounts of up to 90% versus On-Demand pricing. AWS can reclaim them with a two-minute warning, making them ideal for workloads that can tolerate interruption.
When to Use Spot
- Data processing and ETL pipelines
- Machine learning training jobs
- CI/CD build agents
- Rendering and media transcoding
- Load testing environments
Mixed Instance Strategy
Use a mixed instance policy in your Auto Scaling Group — combine Spot with a small On-Demand base. Specify multiple instance families (m5, m5a, m5n) in the same capacity pool to reduce interruption frequency.
aws autoscaling create-auto-scaling-group \
--mixed-instances-policy '{
"InstancesDistribution": {
"OnDemandBaseCapacity": 1,
"OnDemandPercentageAboveBaseCapacity": 0,
"SpotAllocationStrategy": "capacity-optimized"
}
}'Handling Interruptions
Poll the EC2 IMDS endpoint for the termination notice:
http://169.254.169.254/latest/meta-data/spot/termination-timeOn detection, checkpoint state and exit cleanly within the two-minute window. For Kubernetes, use the AWS Node Termination Handler to cordon and drain the node automatically.