Spot Instances and Cost-Efficient Compute
Learn how to use EC2 Spot Instances and mixed instance fleets to dramatically reduce compute costs while handling interruptions gracefully.
Spot Instances and Cost-Efficient Compute is a free AWS for Backend Developers (EC2, S3, RDS, Lambda) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS for Backend Developers (EC2, S3, RDS, Lambda) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Are Spot Instances?
Spot Instances let you use spare EC2 capacity at discounts of up to 90% versus On-Demand pricing.
The catch: AWS can reclaim them with a short warning when it needs the capacity back.
On-Demand vs Reserved vs Spot
Three pricing models:
- On-Demand — pay per second, no commitment, full price
- Reserved / Savings Plans — commit for 1-3 years, big discount
- Spot — cheapest, but interruptible
Good Workloads for Spot
Spot shines for fault-tolerant, flexible workloads:
- Batch processing and data analysis
- CI/CD build runners
- Stateless web tiers behind a load balancer
- Containerized jobs
The Interruption Notice
Before reclaiming a Spot Instance, AWS sends a two-minute interruption notice via instance metadata. Your app should check for it and shut down gracefully.
curl http://169.254.169.254/latest/meta-data/spot/instance-actionRequesting a Spot Instance
You can request Spot capacity through the CLI, an Auto Scaling group, or a Spot Fleet. Here is a simple run-instances request.
aws ec2 run-instances \
--image-id ami-123 \
--instance-type c6g.large \
--instance-market-options 'MarketType=spot'Spot in Auto Scaling Groups
Auto Scaling groups support a mixed instances policy: combine On-Demand and Spot in one group, so a baseline stays reliable while Spot adds cheap capacity.
Diversification Reduces Risk
Spreading requests across many instance types and Availability Zones lowers the chance all your capacity is interrupted at once. This is called diversification.
Capacity Rebalancing
Capacity Rebalancing proactively launches a replacement instance when a Spot Instance is at elevated risk of interruption, before the two-minute notice fires.
Handling State
Because instances can vanish, keep state off the instance. Store data in S3, RDS, or DynamoDB, and treat compute as disposable.
Spot with Containers
ECS and EKS both support Spot capacity. The orchestrator reschedules tasks/pods when an instance is reclaimed, making Spot especially safe for containerized workloads.
Cost Strategy Summary
A balanced strategy:
- Reserved/Savings Plans for steady baseline load
- On-Demand for unpredictable bursts
- Spot for flexible, fault-tolerant capacity
Quick Check
Test your Spot knowledge.
Recap
You learned cost-efficient compute:
- Spot offers up to 90% savings but is interruptible
- Watch the two-minute interruption notice
- Diversify across types and AZs
- Mix Spot, On-Demand, and Reserved for the best balance
Treat compute as disposable and Spot becomes a powerful cost lever.
Frequently asked questions
Is the “Spot Instances and Cost-Efficient Compute” lesson free?
Yes — the full text of “Spot Instances and Cost-Efficient Compute” is free to read here on the web, and the AWS for Backend Developers (EC2, S3, RDS, Lambda) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS for Backend Developers (EC2, S3, RDS, Lambda) course, upgrade to CoddyKit PRO.
What will I learn in “Spot Instances and Cost-Efficient Compute”?
Learn how to use EC2 Spot Instances and mixed instance fleets to dramatically reduce compute costs while handling interruptions gracefully. You practise AWS for Backend Developers (EC2, S3, RDS, Lambda) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS for Backend Developers (EC2, S3, RDS, Lambda)?
No prior experience is required. AWS for Backend Developers (EC2, S3, RDS, Lambda) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Spot Instances and Cost-Efficient Compute” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS for Backend Developers (EC2, S3, RDS, Lambda) lesson?
Yes. Every AWS for Backend Developers (EC2, S3, RDS, Lambda) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- EC2 Instance Types and AMIs
- Implementing Auto Scaling Groups
- Load Balancing with ELB
- Spot Instances and Cost-Efficient Compute