Amazon Elastic Compute Cloud
User Guide (API Version 2013-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Canceling Spot Instance Requests

If you no longer want your Spot request, you can cancel it. You can only cancel Spot Instance requests that are open or active. Your Spot request is open when your request has not yet been fulfilled and no instances have been launched. Your Spot request is active when your request has been fulfilled, and Spot Instances have launched as a result. If your Spot request is active and has an associated running Spot Instance, canceling the request does not automatically terminate the instance: You must terminate the running Spot Instance manually.

Note

Make sure you have set up the prerequisites for working with Amazon EC2. If you haven't, go to Prerequisites for Using Spot Instances.

Your Spot request can be in other states in addition to open and active. For more information, see Spot Instance Request States. You can then track the status of each of the requests separately. For information about tracking Spot requests, see Tracking Spot Requests with Bid Status Codes.

A persistent Spot request will try to relaunch a Spot Instance whenever it is interrupted or terminated. If you want to end both the Spot request and its Spot Instance, make sure you cancel the Spot request before you terminate the Spot Instance to ensure that the request doesn’t launch a new instance.

AWS Management Console

To cancel Spot Instance requests

  1. From the Amazon EC2 console, click Spot Requests in the navigation pane.

    The console displays a list of Spot Instance requests.

  2. Select the Spot requests you want to cancel and click the Cancel button.

  3. If you don’t want the associated Spot Instances to continue running, you can cancel them. Select them in the Instances page, then right-click and select Terminate.

Command Line Tools

To cancel Spot Instance requests

  1. Enter the following command to see your Spot Instance requests:

    PROMPT> ec2-describe-spot-instance-requests

    Amazon EC2 returns output similar to the following:

    SPOTINSTANCEREQUEST   sir-09fb0a04   0.04   one-time   Linux/UNIX   closed   
    2010-04-06T10:03:09+0200   ami-b232d0db   m1.small   gsg-keypair   default    monitoring-disabled
  2. To cancel the request, enter the following:

    PROMPT> ec2-cancel-spot-instance-requests sir-09fb0a04

    Amazon EC2 returns output similar to the following:

    SPOTINSTANCEREQUEST     sir-09fb0a04    canceled
  3. To terminate the instances associated with the Spot request you just canceled, enter the following:

    PROMPT> ec2-terminate-instances i-48cd4829

    Amazon EC2 returns output similar to the following:

    INSTANCE     i-48cd4829    running shutting-down

Tip

You can filter the list of Spot Instance requests to return only certain EC2 instance types. For more information about how to filter the results, go to ec2-describe-spot-instance-requests in the Amazon Elastic Compute Cloud Command Line Reference.

API

To cancel Spot Instance requests

  1. Construct the following Query request to see your Spot Instance requests.

    https://ec2.amazonaws.com/
    ?Action=DescribeSpotInstanceRequests
    &...auth parameters...

    Following is an example response.

    <DescribeSpotInstanceRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
      <spotInstanceRequestSet>
          <item>
             <spotInstanceRequestId>sir-8675309a</spotInstanceRequestId>
             <spotPrice>0.32</spotPrice>
             <type>one-time</type>
             <state>open</state>
             <fault/>
             <validFrom/>
             <validUntil/>
             <launchGroup/>
             <availabilityZoneGroup>MyAzGroup</availabilityZoneGroup>
             <launchSpecification>
                <imageId> i-43a4412a</imageId>
                <keyName>MyKeypair</keyName>
                <groupSet>websrv</groupSet>
                <instanceType>m1.small</instanceType>
             </launchSpecification>
             <instanceId>i-123345678</instanceId>
             <createTime>2009-10-19T00:00:00+0000</createTime>
           <productDescription>Linux/UNIX</productDescription>
           <launchedAvailabilityZone>us-east-1c</launchedAvailabilityZone>
          </item>
       </spotInstanceRequestSet>
    </DescribeSpotInstanceRequestsResponse>
  2. Construct a Query request to cancel the Spot Instance requests.

    https://ec2.amazonaws.com/
    ?Action=CancelSpotInstanceRequests
    &SpotInstanceRequestId.1=sir-8675309a
    &...auth parameters...

    Following is an example response.

    <CancelSpotInstanceRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2013-02-01/">
      <spotInstanceRequestId>sir-8675309a</spotInstanceRequestId>
    </CancelSpotInstanceRequestsResponse>

Tip

You can filter the list of Spot Instance requests to return only certain EC2 instance types. For more information about how to filter the results, go to DescribeSpotInstanceRequests in the Amazon Elastic Compute Cloud API Reference.

What do you want to do next?