The most important fact about AWS Spot instances is that they can provide significant cost savings compared to On-Demand instances. Spot instances allow you to bid on unused Amazon EC2 capacity and can be up to 90% less expensive than On-Demand instances. This makes them an excellent option for workloads that can be interrupted if the Spot price exceeds your bid price or if the capacity is needed for On-Demand or Reserved Instance customers.
This article provides the most important information about AWS Spot instances, including an overview of AWS EC2 Spot pricing. Let’s get started!
Table of Contents
What is a Spot instance in AWS?
An AWS Spot instance in Amazon Web Services (AWS) is an EC2 (Elastic Compute Cloud) instance that allows users to bid on unused Amazon EC2 capacity and run those instances for a significantly lower cost than On-Demand instances.
Spot instances are well-suited for flexible, short-term, and interruption-tolerant workloads, such as BigData, containerized workloads, CI/CD, stateless web servers, high-performance computing (HPC), Machine Learning models training, and AWS Batch. The price of a Spot instance can frequently change depending on the supply and demand for spare EC2 capacity. If the Spot price exceeds the user’s bid price, their instance will be terminated automatically within two minutes time interval. AWS Spot Instance pricing allows users to bid on unused EC2 instances and save up to 90% on the On-Demand price.
You can always check historical prices for specific AWS Spot instance types:
There are two types of Spot instance requests you can make in AWS:
- One-time request: this Spot instance request launches a single Spot instance for a specified period of time. The instance is terminated when the specified period expires or the Spot price exceeds the bid price.
- Persistent requests: this Spot instance request is used to launch multiple Spot instances that continue to run until they are terminated by the user or terminated by Amazon EC2 because the Spot price exceeds the bid price. Persistent requests are useful for applications that can handle interruptions.
Please, keep in mind that starting from December 31, 2022, there’s no longer way to define a duration for Spot instances.
Users can launch Spot Instances using the AWS CLI, SDK, or Web Management Console by specifying the maximum price they are willing to pay for the instance.
Spot instance limits
There are several limits on the number of running Spot instances vCPUs and requested Spot Instances per AWS account per Region. These are soft limits and can be expanded by AWS Support.
When would you use Spot Instances?
Spot instances are typically used for workloads that are flexible and can handle interruption, such as:
- Big data processing: Applications like Apache Hadoop, Apache Spark, and Apache Storm can leverage the low-cost and high availability of Spot instances to process large amounts of data.
- Containerized workloads: Applications running in containers can be easily moved between On-Demand and Spot instances, making it easy to take advantage of the low cost of Spot instances.
- Machine Learning models training: Managed Spot Training with Amazon SageMaker allows you to save up to 70-90% on your Amazon SageMaker Training Jobs.
- CI/CD: Continual integration and deployment workloads can be run on Spot instances, as they can be easily terminated and replaced if the Spot price increases.
- High-performance computing: Applications that require a large number of CPU or GPU resources can be run on Spot instances to save costs.
- Web servers: Applications that handle variable traffic can use Spot instances to handle periods of high traffic and then scale down when traffic decreases.
- Test and development: Spot instances can be used for test and development workloads as they are cost-effective alternatives to On-Demand instances.
It is important to note that since EC2 Spot instances can be terminated when the Spot price exceeds the maximum bid price, it’s important to design the application to handle interruption and to save the data in durable storage if required.
What are the best practices for running Spot instances in AWS?
Here are some best practices for running Spot instances in AWS:
- Design your application to handle interruption: Since Spot instances can be terminated, it’s important to design your application to handle these interruptions.
- Use Auto Scaling groups: You can use Auto Scaling groups to launch replacement instances when a Spot instance is terminated automatically.
- Monitor Spot instance termination notice: You can check the EC2 metadata service every 5 seconds to monitor Spot instance interruptions notices and have a chance to shut down your application gracefully.
- Use the EventBridge: You can use but do not rely (“best effort delivery“) on EventBridge “EC2 Spot Instance Interruption Warning” notifications when a Spot instance is going to be terminated.
- Use AWS CloudTrail: you can check AWS CloudTrail logs for the BidEvictedEvent event to see whether Amazon EC2 terminated the Spot Instance.
- Monitor EC2 Spot Instance Cost: we recommend you check the Diving Deeper into EC2 Spot Instance Cost and Operational Practices article to maximize your benefits of using Spot instances.
- Get familiar with Spot lifecycle: Understanding the Spot request status will help you track your Spot Instance requests and plan your use of Spot Instances
- Do not use Spot Fleet API: You must rely on Auto Scaling Groups or CreateFleet API (EC2 Fleet API) to launch and manage a fleet of Spot instances to help ensure you have the number of instances you need.
- Use integrated AWS services to manage Spot Instances: whenever possible, rely on Amazon EMR, ECS, Batch, EKS, SageMaker, Elastic Beanstalk, and Amazon GameLift. These services will help you eliminate Spot instances’ management heavy lifting.
- Use AWS Fault Injection Simulator to test how your application handles the Spot instance interruption process.
- Use the Spot placement score and AWS Spot Instance advisor: these tools allow you to select optimal Regions or Availability Zones for your workloads that can use multiple instance types and have the lowest chance of interruption.
By following these best practices, you can take advantage of the low cost of Spot instances while minimizing interruption to your application.
Free hands-on AWS workshops
We highly recommend you check out the following free hands-on AWS Spot Instances workshop:
What’s the difference between Spot, On-Demand, and Reserved Instances?
Spot instances are a cost-effective option for workloads that can handle interruption, On-Demand instances are a good option for applications with unpredictable or spiky usage patterns, and Reserved Instances are a cost-effective option for applications with steady state or predictable usage.