A clear breakdown of AWS Spot Requests vs Spot Instances, and how they work together:
What Are Spot Instances?
- Spot Instances
are unused EC2 capacity offered at a discount (up to 90% cheaper
than On-Demand).
- They can be terminated by AWS at any time if the
capacity is needed back or your max bid is exceeded.
- Great for fault-tolerant or flexible workloads (e.g.,
batch jobs, CI/CD, big data, stateless microservices).
What Is a Spot Request?
A Spot Request is how you ask
AWS to give you a Spot Instance.
There are two types:
Type |
Description |
One-time |
AWS launches the Spot Instance
once. After it runs (or is terminated), it’s done. |
Persistent |
AWS will keep trying to
launch a new instance if the existing one is terminated (e.g., due to
capacity issues or manual termination). |
Relationship Between the Two
- You submit a Spot Request, and if capacity and
price allow, a Spot Instance is launched.
- If you terminate the instance but leave the request
active (persistent), AWS may launch another.
- To prevent that, you need to cancel the request before
terminating the instance.
Lifecycle Flow (Typical)
- You submit a Spot Request via Console, CLI, SDK, or IaC
(like Terraform).
- AWS evaluates if there’s capacity and if your max price
is acceptable.
- If yes, AWS launches a Spot Instance.
- If the request is persistent, AWS will monitor
and attempt re-launches if needed.
In AWS, Spot Instances are
tied to Spot Requests — and here's why the request must be canceled before
terminating the instance:
Spot Request Auto-Replacement
When you launch a Spot Instance via
a persistent spot request, AWS assumes you want that instance type at
that price continuously. So if you just terminate the instance
without canceling the request:
- AWS will automatically launch a replacement instance (because the request is still active).
- That means your cost continues, and you might
lose control over what's running.
Canceling the Spot Request First
When you cancel the spot request
first, you tell AWS:
- "I don't want this anymore — stop trying to
fulfill this request."
- Then when you terminate the instance, AWS won't try to replace
it.
One-time vs. Persistent Spot Requests
- Persistent spot request: Keeps trying to fulfill the request even after
termination.
- One-time spot request: If fulfilled and the instance is terminated, AWS won't try to replace it. But still best practice to cancel it for clarity and cost control.
twtech Best Practice:
- First, cancel
the spot request.
- Second,
terminate the instance.
- Always cancel persistent requests before terminating instances to avoid
auto-replacement.
- Clean up old or
failed spot requests to avoid confusion and extra billing.
- Use Auto
Scaling Groups with Mixed Instances or EC2 Fleet for more
control and resiliency.
No comments:
Post a Comment