Back to blog

Complete Guide to AWS Spot Instances

Alon Berger

Product Marketing Manager, Intel Granulate

What Are AWS Spot Instances? 

AWS Spot Instances are an offering from Amazon Web Services (AWS) that allows you to bid on spare Amazon EC2 computing capacity. They provide discounts of up to 90%, making them an important component of an organization’s cloud cost management strategy.

Spot instances are particularly useful for workloads that are not time-sensitive and can withstand occasional interruptions. These instances can be interrupted by AWS with short notice (typically 2 minutes) if AWS needs the capacity back or if the current spot price exceeds your maximum price. Despite this, with careful planning and management, AWS Spot instances can be an effective tool for managing your AWS costs.

In this article:

Key AWS Spot Instances Concepts 

Spot Capacity Pool

A Spot capacity pool in AWS is a specific combination of instance type, operating system, and availability zone. When you request a Spot instance, you’re actually bidding on a spot in a specific capacity pool. The more flexible you can be with your capacity pool selection, the better your chances of getting your spot instance request fulfilled.

Spot capacity pools are significant because the price of an instance depends on supply and demand for a specific capacity pool. If the demand is high and the supply is low in a particular capacity pool, the Spot price will be higher. On the other hand, if the demand is low and the supply is high, the Spot price will be lower.

New call-to-action

Spot Price

The Spot price is the current price that you would pay for a spot instance. It is determined by AWS based on the supply and demand for Spot instances in a specific capacity pool. This price fluctuates throughout the day as supply and demand conditions change.

When you request a Spot instance, you specify the maximum price you’re willing to pay per hour for each instance. If the spot price is less than or equal to your maximum price, your request is fulfilled and your instances are launched. If the Spot price goes above your maximum price, your instances are terminated.

Spot Instance Request

A Spot instance request is a bid that you place for one or more Spot instances. When you make a request, you specify the maximum price you’re willing to pay per hour, the instance type, the availability zone, and other parameters.

There are three types of spot instance requests: 

  • One-time request: You make a request and AWS fulfills it once. 
  • Persistent request: Automatically placed again after your spot instances are terminated due to a price increase or a capacity shortage. 
  • Spot Fleet request: A collection of requests that are managed together. When AWS fulfills the request, you can manage your spot instances as a group.

EC2 Instance Rebalance Recommendation

An EC2 instance rebalance recommendation is a feature that provides an early warning when your Spot instance is at risk of interruption. This warning gives you the chance to manage the interruption in a way that best suits your application.

When AWS predicts that your instance will be interrupted, it sends an EC2 instance rebalance recommendation. This allows you to proactively manage the interruption, for example, by saving the state of your workload, draining TCP connections, or even moving the workload to a different Spot instance. Note that AWS does not guarantee it will provide rebalancing recommendations, and it might terminate Spot instances without prior warning.

Spot Instance Interruption

An interruption is a termination or stop of your Spot instance initiated by AWS. This can happen for two reasons: the Spot price exceeds your maximum price, or AWS needs the capacity back.

When your Spot instance is interrupted, AWS provides a two-minute warning before terminating or stopping your instance. This gives you a small window to save your work and shut down your instance gracefully.

Spot Instances vs. Reserved Instances vs. On-Demand Instances

AWS offers three types of instances: Spot, reserved, and on-demand. Let’s understand the differences between them.

  • Spot instances: Spot instances are surplus AWS resources that are available for immediate use. They are significantly cheaper than on-demand instances. However, AWS can reclaim these resources with just a two-minute warning if a higher bid comes in or if AWS needs the resources back.
  • Reserved instances: Resources that you reserve for a long-term period (one or three years), guaranteeing availability for that duration. This option is suitable for predictable workloads where you know your resource requirements well in advance. Reserved instances offer discounts of up to 72% compared to on-demand pricing.
  • On-demand instances: Let you pay for compute capacity by the hour or second, with no long-term commitments or upfront payments. You can increase or decrease your compute capacity depending on the demands of your application and only pay the specified hourly rates for the instances you use. However, this option is also the most expensive.
New call-to-action

When Should You Use Amazon Spot Instances? 

Here are the most common use cases for Spot instances:

Stateless Applications

Stateless applications are a good fit for Spot instances, because if they are interrupted, they can restart and continue serving user requests. This is in contrast to stateful applications where the application needs to remember the previous state and operations for each user.

CI/CD Operations

Spot instances are useful for Continuous Integration and Continuous Deployment (CI/CD) operations. These tasks typically involve short-lived processes that can tolerate interruptions. If an instance is reclaimed, the task can simply be restarted on a new instance.

Big Data

For big data workloads that involve processing large amounts of data in parallel, Spot instances can be a cost-effective solution. These types of tasks can typically tolerate the loss of a few nodes without a significant impact on the overall job.

Distributed Databases

Distributed databases, which spread data across multiple nodes to ensure high availability and reliability, can also benefit from Spot instances. If an instance is reclaimed, the database can continue to function with the remaining nodes until a new Spot instance is obtained.

Related content: Read our guide to optimizing AWS costs

How Can You Check Spot Instance Price History?

When using AWS Spot instances, it’s crucial to understand how to check their price history. Spot prices are determined by Amazon’s supply and demand for unused EC2 capacity, so the prices fluctuate accordingly. This fluctuation is why it’s important to keep track of the Spot instance price history.

To check the Spot instance price history using the AWS Management Console:

  1. Navigate to the EC2 dashboard in the AWS Management Console
  2. Under the main navigation menu, select Spot Requests.
  3. Click on Pricing History. Here, you can view the price history for spot instances, which is usually displayed as a graph.

You can also check the Spot instance price using:

  • The AWS CLI, by running the describe-spot-price-history command. This lets you retrieve the price history for a specific instance type within a specific time range. 
  • The AWS SDKs, which allow you to write custom scripts and applications to retrieve and analyze Spot instance price history.

Best Practices for Using AWS Spot Instances 

These practices are designed to maximize the efficiency of your Spot instances and help you get the most value for your money.

Prepare Individual Instances for Interruptions

Given that Spot instances are unused EC2 capacity that Amazon rents out at reduced prices, they are subject to interruptions. To handle these interruptions effectively, it’s crucial to prepare your instances.

One way to prepare your instances for interruptions is by setting up interruption handlers. These handlers are scripts that respond to interruption warnings from AWS by performing specific actions, such as saving work, draining connections, or even moving work to on-demand instances. Another way is to design your applications for fault-tolerance or use platforms that have built-in redundancy and high availability.

Be Flexible in Terms of Instance Types and Availability Zones

If you are willing to be flexible in terms of instance types and Availability Zones, you can increase your chances of having your Spot instance request fulfilled. Different instance types offer different levels of performance and capacity, and their prices can vary significantly. Specifying multiple instance types in your Spot instance request can increase your chances of obtaining an instance at a lower price.

Use EC2 Auto Scaling Groups or Spot Fleet

To effectively manage your total capacity, you can use EC2 Auto Scaling groups or the Spot Fleet feature. Both of these features provide automated tools for managing your Spot instances.

EC2 Auto Scaling groups allow you to automatically adjust your Spot instance capacity based on demand. You can set up scaling policies that increase or decrease your Spot instance capacity as needed, ensuring that you always have the right amount of capacity.

Spot Fleet is a collection of spot instances and, optionally, on-demand instances. The ability to combine spot and on-demand instances is quite powerful, because it gives you a fallback option if spot instances are terminated. The service attempts to launch the number of instances needed to meet the target capacity that you specified in the Spot Fleet request.

Use Proactive Capacity Balancing

Balancing capacity involves constantly monitoring your Spot instance capacity and managing it proactively to minimize the risk of interruptions.

This can be achieved by using AWS’s Capacity Rebalancing feature, which integrates with EC2 Auto Scaling groups and Spot Fleet. When AWS predicts that a Spot instance will be interrupted, Capacity Rebalancing automatically attempts to replace it with a new one, reducing the impact of the interruption.

New call-to-action

AWS Cost Optimization with Intel Granulate

Intel Granulate empowers AWS users with real-time, continuous performance optimization and capacity management, leading to reduced cloud costs. Available in the AWS marketplace, Intel Granulate’s solution operates on the application-level to optimize workloads and capacity management automatically and continuously without the need for code alterations.

Intel Granulate supports AWS customers by optimizing the most popular compute services including EC2, EKS, ECS, EMR and Databricks. With Intel Granulate, AWS customers are seeing improvements in their job completion time, throughput, response time, and carbon footprint, while realizing up to 45% cost savings.

Optimize application performance.

Save on cloud costs.

Start Now
Back to blog