Amazon Elastic Compute Cloud
User Guide for Linux Instances

Spot Instance Interruptions

Demand for Spot Instances can vary significantly from moment to moment, and the availability of Spot Instances can also vary significantly depending on how many unused EC2 instances are available. In addition, no matter how high you bid, it is still possible that your Spot Instance will be interrupted. Therefore, you must ensure that your application is prepared for a Spot Instance interruption. We strongly recommend that you do not use Spot Instances for applications that can't be interrupted.

The following are the possible reasons that Amazon EC2 will interrupt your Spot Instances:

  • Price—The Spot price is greater than your bid price.

  • Capacity—If there are not enough unused EC2 instances to meet the demand for Spot Instances, Amazon EC2 interrupts Spot Instances, starting with those instances with the lowest bid prices. If there are several Spot Instances with the same bid price, the order in which the instances are interrupted is determined at random.

  • Constraints—If your request includes a constraint such as a launch group or an Availability Zone group, these Spot Instances are terminated as a group when the constraint can no longer be met.

Interruption Behavior

You can specify whether Amazon EC2 should stop or terminate Spot Instances when they are interrupted. The default is to terminate Spot Instances when they are interrupted. You can change the behavior so that Amazon EC2 stops Spot Instances when they are interrupted if the following requirements are met.


  • For a Spot Instance request, the type must be persistent, not one-time. You cannot specify a launch group in the Spot Instance request.

  • For a Spot Fleet request, the type must be maintain, not request.

  • The root volume must be an EBS volume, not an instance store volume.

After a Spot Instance is stopped by the Spot service, it can only be restarted by the Spot service, and only using the same launch configuration. When capacity is available that matches the Availability Zone and instance type of a Spot Instance that is stopped, the Spot Instance is started. With Spot Fleet, if capacity is available only with a different Availability Zone or instance type, Spot Fleet launches a new Spot Instance using the launch configuration with available capacity.

While a Spot Instance is stopped, you can modify some of its instance attributes, but not the instance type. If you detach or delete an EBS volume, it is not attached when the Spot Instance is started. If you detach the root volume and the Spot service attempts to start the Spot Instance, instance start fails and the Spot service terminates the stopped instance.

You can terminate a Spot Instance while it is stopped. If you cancel a Spot request or a Spot Fleet, the Spot service terminates any associated Spot Instances that are stopped.

While a Spot Instance is stopped, you are charged only for the EBS volumes, which are preserved. With Spot Fleet, if you have many stopped instances, you can exceed the limit on the number of EBS volumes for your account.

Preparing for Interruptions

Here are some best practices to follow when you use Spot Instances:

  • Choose a reasonable bid price. Your bid price should be high enough to make it likely that your request will be fulfilled, but not higher than you are willing to pay. This is important because if the supply is low for an extended period of time, the Spot price can remain high during that period because it is based on the highest bid prices. We strongly recommend against bidding above the price for On-Demand Instances.

  • Ensure that your instance is ready to go as soon as the request is fulfilled by using an Amazon Machine Image (AMI) that contains the required software configuration. You can also use user data to run commands at start-up.

  • Store important data regularly in a place that won't be affected when the Spot Instance terminates. For example, you can use Amazon S3, Amazon EBS, or DynamoDB.

  • Divide the work into small tasks (using a Grid, Hadoop, or queue-based architecture) or use checkpoints so that you can save your work frequently.

  • Use Spot Instance interruption notices to monitor the status of your Spot Instances.

  • While we make every effort to provide this warning as soon as possible, it is possible that your Spot Instance will be terminated before the warning can be made available. Test your application to ensure that it handles an unexpected instance termination gracefully, even if you are testing for interruption notices. You can do so by running the application using an On-Demand Instance and then terminating the On-Demand Instance yourself.

Spot Instance Interruption Notices

The best way to protect against Spot Instance interruption is to architect your application to be fault tolerant. In addition, you can take advantage of Spot Instance interruption notices, which provide a two-minute warning before Amazon EC2 must interrupt your Spot Instance. We recommend that you check for these warnings every 5 seconds.

This warning is made available to the applications on your Spot Instance using an item in the instance metadata. You should use the instance-action item. The termination-time item is maintained for backward compatibility.


If your Spot Instance is marked to be stopped or terminated by the Spot service, the instance-action item is present in your instance metadata. You can retrieve it as follows.

[ec2-user ~]$ curl

The instance-action item specifies the action (stop or terminate) and the approximate time in UTC when the action will occur. The following example indicates the time that this instance will be stopped:

{"action": "stop", "time": "2017-09-18T08:22:00Z"}

The following example indicates the time that this instance will be terminated:

{"action": "terminate", "time": "2017-09-18T08:22:00Z"}


If your Spot Instance is marked for termination by the Spot service, the termination-time item is present in your instance metadata. This item is maintained for backward compatibility. You can retrieve it as follows.

[ec2-user ~]$ if curl -s | grep -q .*T.*Z; then echo terminated; fi

The termination-time item specifies the approximate time in UTC when the instance will receive the shutdown signal. For example:


If Amazon EC2 is not preparing to terminate the instance, or if you terminated the Spot Instance yourself, the termination-time item is either not present (so you receive an HTTP 404 error) or contains a value that is not a time value.

If Amazon EC2 fails to terminate the instance, the Spot bid status is set to fulfilled. Note that termination-time remains in the instance metadata with the original approximate time, which is now in the past.