Amazon EC2 Spot Instances

Spot Instances are a new way to purchase and consume Amazon EC2 Instances. They allow customers to bid on unused Amazon EC2 capacity and run those instances for as long as their bid exceeds the current Spot Price. The Spot Price changes periodically based on supply and demand, and customers whose bids meet or exceed it gain access to the available Spot Instances. Spot Instances are complementary to On-Demand Instances and Reserved Instances, providing another option for obtaining compute capacity.

For customers with flexibility in when their applications can run, Spot Instances can significantly lower their Amazon EC2 costs. Additionally, Spot Instances can provide access to large amounts of additional capacity for applications with urgent needs. Just a few examples of categories of applications well-suited to Spot Instances are:

  • Image and video processing, conversion and rendering
  • Scientific research data processing
  • Financial modeling and analysis




This page contains the following categories of information. Click to jump down:




How Spot Instances Work

Spot Instances enable you to bid for unused Amazon EC2 capacity. Instances are charged the Spot Price set by Amazon EC2, which fluctuates periodically depending on the supply of and demand for Spot Instance capacity. To use Spot Instances, you place a Spot Instance request, specifying the instance type, the region desired, the number of Spot Instances you want to run, and the maximum price you are willing to pay per instance hour. To determine how that maximum price compares to past Spot Prices, the Spot Price history is available via the Amazon EC2 API and the AWS Management Console. If your maximum price bid exceeds the current Spot Price, your request is fulfilled and your instances will run until either you choose to terminate them or the Spot Price increases above your maximum price (whichever is sooner).

It’s important to note two points:

  1. You will often pay less per hour than your maximum bid price. The Spot Price is adjusted periodically as requests come in and available supply changes. Everyone pays that same Spot Price for that period regardless of whether their maximum bid price was higher. You will never pay more than your maximum bid price per hour.
  2. If you’re running Spot Instances and your maximum price no longer meets or exceeds the current Spot Price, your instances will be terminated. This means that you will want to make sure that your workloads and applications are flexible enough to take advantage of this opportunistic capacity. It also means that if it’s important for you to run Spot Instances uninterrupted for a period of time, it’s advisable to submit a higher maximum bid price, especially since you often won’t pay that maximum bid price.

Spot Instances perform exactly like other Amazon EC2 instances while running, and like other Amazon EC2 instances, Spot Instances can be terminated when you no longer need them. If you terminate your instance, you will pay for any partial hour (as you do for On-Demand or Reserved Instances). However, if the Spot Price goes above your maximum price and your instance is terminated by Amazon EC2, you will not be charged for any partial hour of usage.

Understanding Spot Requests and Spot Price

Spot Instances are available for EC2 instance types on both Linux/UNIX and Microsoft Windows Server operating systems. The key differences between Spot Instances and On-Demand Instances are that your instance may not start immediately, the hourly price is variable, and Amazon EC2 may terminate individual Spot Instances. This section describes how these work with a simple example.

Understanding when your instance will start

Let’s assume you decide to place a Spot request for one Standard Small (m1.small) instance in the US East – Northern Virginia Region. You can see from the Spot Price history in the AWS Management Console or by using the Amazon EC2 API that the Spot Price has recently fluctuated about every 1-2 hours between $0.030/hr and $0.060/hour, and is currently $0.050/hr. You decide you want to bid a maximum price of $0.045/hr. You create your request by using the AWS Management Console or making a request through the Amazon EC2 API. Because your maximum price is less than the current Spot Price, no instance is launched and your request remains in a pending state.

Two hours later, the Spot Price drops to $0.045/hr. At this point, your request may or may not start running. This is because your maximum price exactly equals the current Spot price and there may be more requests at this price than can be fulfilled. Let’s assume your instance does not start. Thirty minutes later, the Spot price drops to $0.039/hr. Because this is below your maximum price, a Spot Instance will soon be launched and you will expect to pay $0.039/hr for the instance’s first complete hour.

Understanding when your instance could get terminated

Continuing our example, three hours later the Spot price increases to $0.043/hr. You will now pay $0.043/hr if you continue to run the instance. You would not expect your instance to be shut down by Amazon EC2 because the Spot Price is still lower than your maximum price.

One hour later, the Spot price increases to $0.045/hr. At this point, your instance may or may not get terminated (based on available supply), and in this case it continues to run. You will be charged $0.045/hr for continuing to run this instance.

Finally, four hours later, the Spot price increases to $0.055/hr. Because this is greater than your maximum price, your Spot Instance is terminated by Amazon EC2. You will not be charged for any partial hour that your instance consumed since it was terminated by Amazon EC2.

Spot Features

There are a number of features that make it easier to write applications that take advantage of Spot Instances:

Persistent Requests: Spot Instance requests can be one-time or persistent. A one-time request will only be satisfied once; a persistent request will remain in consideration after each instance termination. This means that with a persistent request, after your request has been satisfied and your instance has been terminated—by you or by Amazon EC2—your request will be submitted again automatically with the same parameters as your initial request. A persistent request will continue submitting the request until you cancel it. A persistent request is useful when you have a large amount of computing that you want to get done but only below a certain price. By using a persistent request, you can launch instances any time the Spot Price is below your maximum price and steadily work through your task.

Launch Groups and specifying Availability Zones: If you want to run a cluster of instances that always launch and terminate simultaneously, there are two options which can be useful. First, you can specify a Launch Group in your request. This will tell Amazon EC2 to launch those instances only if all the instances in the request can be satisfied. Second, you can choose to specify an Availability Zone Group that ensures your instances will be launched together in a single Availability Zone. These restrictions can be useful for many applications; however, if not required, avoiding them will increase the chance that your request can be fulfilled.

Price History: Amazon EC2 provides a history of the Spot Price for each instance type in each Region via the AWS Management Console and the Amazon EC2 APIs. Spot Price history is valuable in helping you to determine how frequently your request would have been fulfilled in the past, given the maximum you are willing to pay to run your job. Alternately, it can be used to help determine how high to set your maximum price to increase the likelihood that your instance will continue to run given past Spot Price history.

Architecting Applications to Use Spot Instances

There are a number of best practices to keep in mind when making use of Spot Instances:

Save Your Work Frequently: Because Spot Instances can be terminated without warning, it is important to build your applications in a way that allows you to make progress even if your application is interrupted. There are many ways to accomplish this, two of which include adding checkpoints to your application and splitting your work into small increments. Using Amazon EBS volumes to store your data is one easy way to protect your data.

Test Your Application: When using Spot Instances, it is important to make sure that your application is fault tolerant and will correctly handle interruptions. While we attempt to cleanly terminate your instances, your application should be prepared to deal with an immediate shutdown. You can test your application by running an On-Demand Instance and then terminating it suddenly. This can help you to determine whether or not your application is sufficiently fault tolerant and is able to handle unexpected interruptions.

Track when Spot Instances Start and Terminate: The simplest way to know the current status of your Spot Instances is to monitor your Spot requests and running instances via the AWS Management Console or Amazon EC2 API.

Choose a Maximum Price for Your Request: Remember that the maximum price that you submit as part of your request is not necessarily what you will pay per hour, but is rather the maximum you would be willing to pay to keep it running. You should set a maximum price for your request that is high enough to provide whatever probability you would like that your instances run for the amount of time that you desire within a given timeframe. Use the Spot Price history via the AWS Management Console or the Amazon EC2 API to help you set a maximum price.

Using Spot Instances

Spot Instances can be requested using the AWS Management Console or Amazon EC2 APIs. To start with the AWS Management Console:

  1. Log in to the AWS Management Console, then click the “Amazon EC2” tab.
  2. Click on “Spot Requests” in the navigation pane on the left.
  3. Click on “Pricing History” to open a view of historical pricing selectable by instance type. This will help you choose a maximum price for your request. Pricing shown is specific to the Region selected in the left side navigation pane. You can click on the “Time” column to sort by latest vs earliest pricing history.
  4. Click on “Request Spot Instances” and proceed through the Launch Instance Wizard process, choosing an AMI and instance type. Enter the number of Spot Instances you would like to request, your maximum price and whether the request is persistent or not. After choosing your key pair and security group(s), you are ready to submit your Spot Instance request.

For detailed information on how to request Spot Instances through the Amazon EC2 API, see the Amazon EC2 API Reference in the latest EC2 Technical Documentation.

For a more detailed walk through of using Spot Instances and more information on how to get the most out of Spot Instances, please read Introduction to Spot Instances.

To learn more about the differences between On-Demand, Reserved and Spot Instances, go to Amazon EC2 Instance Purchasing Options.

©2010, Amazon Web Services LLC or its affiliates. All rights reserved.