Jay Taylor's notes

back to listing index

Spot Instance Interruptions - Amazon Elastic Compute Cloud

[web search]
Original source (docs.aws.amazon.com)
Tags: aws spot-instance-termination docs.aws.amazon.com
Clipped on: 2015-07-12

Spot Instance Termination 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 termination notices, which provide a two-minute warning before the Spot service must terminate your Spot Instance.

This warning is made available to the applications on your Spot Instance using an item in the instance metadata. For example, you can check for this warning in the instance metadata periodically (we recommend every 5 seconds) using the following query:

$ if curl -s | grep -q .*T.*Z; then echo terminated; fi

For information about other ways to retrieve instance metadata, see Retrieving Instance Metadata.

If your Spot Instance is marked for termination by the Spot service, the termination-time item is present and it specifies the approximate time in UTC when the instance will receive the shutdown signal. For example:


If the Spot service 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.

Note that while we make every effort to provide this warning the moment that your Spot Instance is marked for termination by the Spot service, it is possible that your Spot Instance will be terminated before Amazon EC2 can make the warning available. Therefore, you must ensure that your application is prepared to handle an unexpected Spot Instance interruption even if you are checking for Spot Instance termination notices.