Menu
Amazon Elastic Compute Cloud
API Reference (API Version 2016-11-15)

RequestSpotInstances

Creates a Spot instance request. Spot instances are instances that Amazon EC2 launches when the bid price that you specify exceeds the current Spot price. Amazon EC2 periodically sets the Spot price based on available Spot Instance capacity and current Spot instance requests. For more information, see Spot Instance Requests in the Amazon Elastic Compute Cloud User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

AvailabilityZoneGroup

The user-specified name for a logical grouping of bids.

When you specify an Availability Zone group in a Spot Instance request, all Spot instances in the request are launched in the same Availability Zone. Instance proximity is maintained with this parameter, but the choice of Availability Zone is not. The group applies only to bids for Spot Instances of the same instance type. Any additional Spot instance requests that are specified with the same Availability Zone group name are launched in that same Availability Zone, as long as at least one instance from the group is still active.

If there is no active instance running in the Availability Zone group that you specify for a new Spot instance request (all instances are terminated, the bid is expired, or the bid falls below current market), then Amazon EC2 launches the instance in any Availability Zone where the constraint can be met. Consequently, the subsequent set of Spot instances could be placed in a different zone from the original request, even if you specified the same Availability Zone group.

Default: Instances are launched in any available Availability Zone.

Type: String

Required: No

BlockDurationMinutes

The required duration for the Spot instances (also known as Spot blocks), in minutes. This value must be a multiple of 60 (60, 120, 180, 240, 300, or 360).

The duration period starts as soon as your Spot instance receives its instance ID. 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.

Note that you can't specify an Availability Zone group or a launch group if you specify a duration.

Type: Integer

Required: No

ClientToken

Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see How to Ensure Idempotency in the Amazon Elastic Compute Cloud User Guide.

Type: String

Required: No

DryRun

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Type: Boolean

Required: No

InstanceCount

The maximum number of Spot instances to launch.

Default: 1

Type: Integer

Required: No

LaunchGroup

The instance launch group. Launch groups are Spot instances that launch together and terminate together.

Default: Instances are launched and terminated individually

Type: String

Required: No

LaunchSpecification

Describes the launch specification for an instance.

Type: RequestSpotLaunchSpecification object

Required: No

SpotPrice

The maximum hourly price (bid) for any Spot instance launched to fulfill the request.

Type: String

Required: Yes

Type

The Spot instance request type.

Default: one-time

Type: String

Valid Values: one-time | persistent

Required: No

ValidFrom

The start date of the request. If this is a one-time request, the request becomes active at this date and time and remains active until all instances launch, the request expires, or the request is canceled. If the request is persistent, the request becomes active at this date and time and remains active until it expires or is canceled.

Default: The request is effective indefinitely.

Type: Timestamp

Required: No

ValidUntil

The end date of the request. If this is a one-time request, the request remains active until all instances launch, the request is canceled, or this date is reached. If the request is persistent, it remains active until it is canceled or this date and time is reached.

Default: The request is effective indefinitely.

Type: Timestamp

Required: No

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

spotInstanceRequestSet

One or more Spot instance requests.

Type: array of SpotInstanceRequest objects

Errors

For information about the errors that are common to all actions, see Common Errors.

Examples

Example 1

This example creates a one-time Spot instance request for two instances. It does not include an Availability Zone or subnet, so Amazon EC2 selects an Availability Zone for you. If your account supports EC2-VPC only, Amazon EC2 launches the instances in the default subnet of the selected Availability Zone. If your account supports EC2-Classic, Amazon EC2 launch the instances in EC2-Classic in the selected Availability Zone.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=RequestSpotInstances &SpotPrice=0.03 &InstanceCount=2 &Type=one-time &LaunchSpecification.ImageId=ami-1a2b3c4d &LaunchSpecification.KeyName=my-key-pair &LaunchSpecification.SecurityGroupId.1=sg-1a2b3c4d &LaunchSpecification.InstanceType=m3.medium &LaunchSpecification.IamInstanceProfile.Name=s3access &AUTHPARAMS

Example 2

The following example includes an Availability Zone. If your account supports EC2-VPC only, Amazon EC2 launches the instances in the default subnet of the specified Availability Zone. If your account support EC2-Classic, Amazon EC2 launches the instances in EC2-Classic in the specified Availability Zone.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=RequestSpotInstances &SpotPrice=0.03 &InstanceCount=2 &Type=one-time &LaunchSpecification.ImageId=ami-1a2b3c4d &LaunchSpecification.KeyName=my-key-pair &LaunchSpecification.SecurityGroupId.1=sg-1a2b3c4d &LaunchSpecification.InstanceType=m3.medium &LaunchSpecification.Placement.AvailabilityZone=us-west-2a &LaunchSpecification.IamInstanceProfile.Name=s3access &AUTHPARAMS

Example 3

The following example includes a subnet. Amazon EC2 launches the instances in the specified subnet. Note that you can specify security groups for EC2-Classic either by ID or by name. You must specify security groups for EC2-VPC by ID.

Sample Request

Copy
https://ec2.amazonaws.com/?Action=RequestSpotInstances &SpotPrice=0.03 &InstanceCount=2 &Type=one-time &LaunchSpecification.ImageId=ami-1a2b3c4d &LaunchSpecification.KeyName=my-key-pair &LaunchSpecification.SecurityGroupId.1=sg-1a2b3c4d &LaunchSpecification.InstanceType=m3.medium &LaunchSpecification.SubnetId=subnet-1a2b3c4d &LaunchSpecification.IamInstanceProfile.Name=s3access &AUTHPARAMS

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: