An overview of how to Requests an AWS Spot Instances.
Focus:
- Tailored for Devops, DevSecops & Cloud Engineers.
Breakdown:
- Intro,
- Using the AWS Management Console,
- Using the AWS CLI,
- The concept: Spot Instances,
- The concept: Spot Request,
- Types of Spot Instances,
- Relationship Between One-time & Persistent Spot Instance,
- Lifecycle Flow (Typical),
- Spot Request Auto-Replacement,
- Canceling the Spot Request First,
- One-time vs. Persistent Spot Requests,
- Best Practice.
Intro:
- AWS Spot Instances can be requested using the AWS Management Console, AWS Command Line Interface (CLI), or the EC2 APIs.
- The most common method is through the console using a launch template or the launch wizard.
- Log in to the AWS Management Console and navigate to the EC2 dashboard.
- In the left navigation pane, click on Spot Requests under the "Instances" or "Instances (new)" section.
- Click the Request Spot Instances button.
- twtech can either select an existing Launch template or manually configure the launch parameters through the wizard. The launch template approach is recommended for reusability.
- If using the wizard, twtech will specify details such as:
- Amazon Machine Image (AMI): The template for twtech instance's operating system and software.
- Instance type(s): Select multiple instance types across different Availability Zones for better availability and cost optimization (using the
price-capacity-optimizedallocation strategy is best practice). - Target capacity: The number of instances twtech wants to run.
- Request type: Choose "one-time" or "persistent". A persistent request attempts to maintain the target capacity even after interruptions.
- Network and security: Configure the VPC, subnet, security groups, and key pair for SSH access.
- User data: Optional script to run when the instance starts.
- Once all parameters are configured & twtech reviews settings and click Submit to place its Spot Instance request.
- AWS will fulfill the request if capacity is available and the current Spot price is at or below the On-Demand price
- twtech doesn't need to set a maximum price.
request-spot-instances command and providing the launch specifications in a JSON file. specification.json file would contain details like the AMI ID, instance type, security group, and key pair information.describe-spot-instance-requests command. - These guides explain how to request AWS Spot Instances using the AWS Management Console and AWS CLI:
The concept: Spot Instances
- Spot Instances
are unused EC2 capacity offered at a discount (up to 90% cheaper
than On-Demand).
- Spot Instances can be terminated by AWS at any time if the capacity is needed back or twtech max bid is exceeded by another bider.
- Spot Instances is Great for fault-tolerant or flexible workloads (e.g.,
batch jobs, CI/CD, big data, stateless microservices).
The concept: Spot Request
A Spot Request is the procedure twtech takes to ask
AWS to give its account a Spot Instance.
Types of Spot Instances:
|
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). |
- twtech submits 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)
- twtech submits a Spot Request via Console, CLI, SDK, or IaC
(like Terraform).
- AWS evaluates if there’s capacity and if twtech 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 twtech wants that instance type at that price continuously.
- So if twtech just terminate the instance without canceling the request:
- AWS will automatically launch a replacement instance (because the request is still active).
- That means twtech cost continues, and it might lose control over what's running.
Canceling the Spot Request First
When twtech cancels the spot request
first, twtech tell AWS:
- "twtech doesn't want the Spot instance anymore — stop trying to
fulfill this request."
- when twtech terminates the instance, AWS won't try to replace Spot Instance anymore.
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:
- Spot Instances can be terminated by AWS at any time if the capacity is needed back or twtech max bid is exceeded by another bider.
- Spot Instances are unused EC2 capacity offered at a discount (up to 90% cheaper than On-Demand).
- Spot Instances is Great for fault-tolerant or flexible workloads (e.g., batch jobs, CI/CD, big data, stateless microservices).
- Persistent spot request: Keeps trying to fulfill the request even after termination.
- Always cancel the spot request first before terminating Spot Instance.
- Second, terminate the instance if no longer needed to avoid cost.
- Always cancel persistent requests before terminating instances to avoid auto-replacement.
- Clean up old or failed spot requests to avoid conflicts and extra billing in envieronment.
- Use Auto Scaling Groups with Mixed Instances or EC2 Fleet for more control and resiliency.
No comments:
Post a Comment