Menu
Amazon Elastic Compute Cloud
User Guide for Linux Instances

Spot Instance Requests

To use Spot instances, you create a Spot instance request that includes the number of instances, the instance type, the Availability Zone, and the maximum price that you are willing to pay per instance hour (your bid). If your bid exceeds the current Spot price, Amazon EC2 fulfills your request immediately. Otherwise, Amazon EC2 waits until your request can be fulfilled or until you cancel the request.

The following illustration shows how Spot requests work. Notice that the action taken for a Spot instance interruption depends on the request type (one-time or persistent). If the request is a persistent request, the request is opened again after your Spot instance is terminated.

The Spot life cycle

Spot Instance Request States

A Spot instance request can be in one of the following states:

  • open—The request is waiting to be fulfilled.

  • active—The request is fulfilled and has an associated Spot instance.

  • failed—The request has one or more bad parameters.

  • closed—The Spot instance was interrupted or terminated.

  • cancelled—You canceled the request, or the request expired.

The following illustration represents the transitions between the request states. Notice that the transitions depend on the request type (one-time or persistent).

Spot request states

A one-time Spot instance request remains active until Amazon EC2 launches the Spot instance, the request expires, or you cancel the request. If the Spot price rises above your bid price, your Spot instance is terminated and the Spot instance request is closed.

A persistent Spot instance request remains active until it expires or you cancel it, even if the request is fulfilled. For example, if you create a persistent Spot instance request for one instance when the Spot price is $0.25, Amazon EC2 launches your Spot instance if your bid price is above $0.25. If the Spot price rises above your bid price, your Spot instance is terminated; however, the Spot instance request is open again and Amazon EC2 launches a new Spot instance when the Spot price falls below your bid price.

You can track the status of your Spot instance requests, as well as the status of the Spot instances launched, through the bid status. For more information, see Spot Bid Status.

Creating a Spot Instance Request

The process for requesting a Spot instance is similar to the process for launching an On-Demand instance. Note that you can't change the parameters of your Spot request, including the bid price, after you've submitted the request.

If you request multiple Spot instances at one time, Amazon EC2 creates separate Spot instance requests so that you can track the status of each request separately. For more information about tracking Spot requests, see Spot Bid Status.

Prerequisites

Before you begin, decide on your bid price, how many Spot instances you'd like, and what instance type to use.

To create a Spot instance request using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, click Spot Requests.

  3. (Optional) To review Spot price trends, click Pricing History. For more information, see Spot Instance Pricing History.

  4. Click Request Spot instances.

  5. On the Choose an Amazon Machine Image page, select an AMI.

  6. On the Choose an Instance Type page, select an instance type and then click Next: Configure Instance Details.

  7. On the Configure Instance Details page, do the following:

    1. (Optional) By default, the request launches one Spot instance. To launch multiple Spot instances, update Number of instances with the number of Spot instances to launch.

    2. The purchasing option Request Spot Instances is selected by default. To create a Spot request, leave this option selected.

    3. In Maximum price, specify the price that you are willing to pay for these Spot instances. If your bid price exceeds the Spot price, the Spot request launches the Spot instances immediately.

      Notice that the current Spot price for each Availability Zones in the region is listed for your information.

    4. (Optional) By default, the request remains in effect until it is fulfilled or you cancel it. To create a request that is valid only during a specific time period, specify Request valid from and Request valid to.

    5. (Optional) By default, the request is a one-time request. To create a persistent Spot request, select Persistent request.

    6. Your account may support the EC2-Classic and EC2-VPC platforms, or EC2-VPC only. To find out which platform your account supports, see Supported Platforms. If your account supports EC2-VPC only, you can launch your instance into your default VPC or a nondefault VPC. Otherwise, you can launch your instance into EC2-Classic or a nondefault VPC.

      To launch into EC2-Classic:

      • Network: Select Launch into EC2-Classic.

      • Availability Zone: Select the Availability Zone to use. To let AWS choose an Availability Zone for you, select No preference.

      To launch into a VPC:

      • Network: Select the VPC, or to create a new VPC, click Create new VPC to go the Amazon VPC console. When you have finished, return to the wizard and click Refresh to load your VPC in the list.

      • Subnet: Select the subnet into which to launch your instance. If your account is EC2-VPC only, select No preference to let AWS choose a default subnet in any Availability Zone. To create a new subnet, click Create new subnet to go to the Amazon VPC console. When you are done, return to the wizard and click Refresh to load your subnet in the list.

      • Auto-assign Public IP: Specify whether your instance receives a public IP address. By default, instances in a default subnet receive a public IP address and instances in a nondefault subnet do not. You can select Enable or Disable to override the subnet's default setting.

    7. Specify the remaining options as you would for an On-Demand instance, and then click Review and Launch. If you are prompted to specify the type of root volume, make your selection and then click Next.

  8. On the Review Instance Launch page, click Edit security groups. On the Configure Security Group page, click Select an existing security group, select or create a security group, and then click Review and Launch.

  9. On the Review Instance Launch page, click Launch.

  10. In the Select an existing key pair or create a new key pair dialog box, select Choose an existing key pair, then select or create a key pair. Click the acknowledgment check box, and then click Request Spot Instances.

  11. On the confirmation page, click View Spot Requests. In the Description tab, notice that the request state is open and the request status is pending-evaluation to start. After the request is fulfilled, the request state is active and the request status is fulfilled.

To create a Spot instance request using the AWS CLI

Use the following request-spot-instances command to create a one-time request:

aws ec2 request-spot-instances --spot-price "0.05" --instance-count 5 --type "one-time" --launch-specification file://specification.json

Use the following request-spot-instances command to create a persistent request:

aws ec2 request-spot-instances --spot-price "0.05" --instance-count 5 --type "persistent" --launch-specification file://specification.json

For example launch specification files, see Spot Request Example Launch Specifications.

Amazon EC2 launches your Spot instance when the Spot price is below your bid. The Spot instance runs until either it is interrupted, or you terminate it yourself. Use the following describe-spot-instance-requests command to monitor your Spot instance request:

aws ec2 describe-spot-instance-requests --spot-instance-request-ids sir-08b93456

Specifying a Duration for Your Spot Instances

Amazon EC2 does not terminate Spot instances with a specified duration (also known as Spot blocks) when the Spot price changes. This makes them ideal for jobs that take a finite time to complete, such as batch processing, encoding and rendering, modeling and analysis, and continuous integration.

You can specify a duration of 1, 2, 3, 4, 5, or 6 hours. The price that you pay depends on the specified duration. To view the current prices for a 1 hour duration or a 6 hour duration, see Spot Instance Prices. You can use these prices to estimate the cost of the 2, 3, 4, and 5 hour durations. When a request with a duration is fulfilled, the price for your Spot instance is fixed, and this price remains in effect until the instance terminates.

When you specify a duration in your Spot request, the duration period for each Spot instance starts as soon as the instance receives its instance ID. The Spot instance runs until you terminate it or the duration period ends. At the end of the duration period, Amazon EC2 marks the Spot instance for termination and provides a Spot instance termination notice, which gives the instance a two-minute warning before it terminates.

To launch Spot instances with a duration using the AWS CLI

To specify a duration for your Spot instances, include the --block-duration-minutes option with the request-spot-instances command. For example, the following command creates a Spot request that launches Spot instances that run for two hours:

aws ec2 request-spot-instances --spot-price "0.050" --instance-count 5 --block-duration-minutes 120 --type "one-time" --launch-specification file://specification.json

To retrieve the cost for Spot instances with a specified duration using the AWS CLI

Use the describe-spot-instance-requests command to retrieve the fixed cost for your Spot instances with a specified duration. The information is in the actualBlockHourlyPrice field.

Finding Running Spot Instances

Amazon EC2 launches a Spot instance when the Spot price is below your bid. A Spot instance runs until either its bid price is no longer higher than the Spot price, or you terminate it yourself. (If your bid price is exactly equal to the Spot price, there is a chance that your Spot instance will remain running, depending on demand.)

To find running Spot instances using the console

  1. Open the Amazon EC2 console.

  2. In the navigation pane, click Spot Requests and select the request. If the request has been fulfilled, the value of the Instance column is the ID of the Spot instance.

  3. Alternatively, in the navigation pane, click Instances. In the top right corner, click the Show/Hide icon, and then select Lifecycle. The value of the Lifecycle column for each instance is either normal or spot.

To find running Spot instances using the AWS CLI

To enumerate your Spot instances, use the describe-spot-instance-requests command with the --query option as follows:

aws ec2 describe-spot-instance-requests --query SpotInstanceRequests[*].{ID:InstanceId}

The following is example output:

[
    {
        "ID": "i-1234567890abcdef0"
    },
    {
        "ID": "i-0598c7d356eba48d7"
    }
]

Alternatively, you can enumerate your Spot instances using the describe-instances command with the --filters option as follows:

aws ec2 describe-instances --filters "Name=instance-lifecycle,Values=spot"

Tagging Spot Instance Requests

To help categorize and manage your Spot instance requests, you can tag them with metadata of your choice. You tag your Spot instance requests in the same way that you tag other any other Amazon EC2 resource. For more information, see Tagging Your Amazon EC2 Resources.

You can tag your Spot instance request when you first create it, or you can assign a tag to the request after you create it.

The tags that you create for your Spot instance requests only apply to the requests. These tags are not added automatically to the Spot instance that the Spot service launches to fulfill the request. You must add tags to a Spot instance yourself when you create the Spot instance request or after the Spot instance is launched.

To add a tag when creating a Spot instance request using the console

  1. When creating a Spot instance request, on the Review page, click Edit tags. You can also complete the tag with the key Name by adding a name for the Spot instance request as the value.

  2. On the Tag Spot Request page, click Create Tag and enter a tag key and tag value.

    Tag Spot Request page.
  3. Click Review and Launch.

To add a tag to an existing Spot instance request using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, click Spot Requests and then select the Spot request.

  3. From the Tags tab, click Add/Edit Tags.

  4. In the Add/Edit Tags dialog box, click Create Tag, specify the key and value for each tag, and then click Save.

    Add/Edit Tags dialog box.
  5. (Optional) You can add tags to the Spot instance launched from the Spot request. On the Spot Requests page, click the ID of the Spot instance in the Instance column for the Spot request. In the bottom pane, select the Tags tab and repeat the process that you used to add tags to the Spot request.

To add a tag to your Spot instance request or Spot instance using the AWS CLI

Use the following create-tags command to tag your resources:

aws ec2 create-tags --resources sir-08b93456 i-1234567890abcdef0 --tags Key=purpose,Value=test

Canceling a Spot Instance Request

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 terminate the instance; you must terminate the running Spot instance manually.

If the Spot request is a persistent Spot request, it returns to the open state so that a new Spot instance can be launched. To cancel a persistent Spot request and terminate its Spot instances, you must cancel the Spot request first and then terminate the Spot instances. Otherwise, the Spot request can launch a new instance.

To cancel a Spot instance request using the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, click Spot Requests, and then select the Spot request.

  3. Click Cancel.

  4. (Optional) If you are finished with the associated Spot instances, you can terminate them. In the navigation pane, click Instances, select the instance, click Actions, select Instance State, and then click Terminate.

To cancel a Spot instance request using the AWS CLI

Use the following cancel-spot-instance-requests command to cancel the specified Spot request:

aws ec2 cancel-spot-instance-requests --spot-instance-request-ids sir-08b93456

If you are finished with the associated Spot instances, you can terminate them manually using the following terminate-instances command:

aws ec2 terminate-instances --instance-ids i-1234567890abcdef0 i-0598c7d356eba48d7