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

ec2-request-spot-instances

Description

Creates a Spot Instance request. Spot Instances are instances that Amazon EC2 starts on your behalf when the maximum 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 about Spot Instances, see Spot Instances in the Amazon Elastic Compute Cloud User Guide.

The short version of this command is ec2rsi.

Syntax

ec2-request-spot-instances ami_id --addressing addressing_type --price price [--instance-count count] [--type type] [--valid-from timestamp] [--valid-until timestamp] [--launch-group group] [--availability-zone-group group] [--user-data data | --user-data-file data-file] [--group group [--group group ...]] [--key key-pair] [--instance-type type] [--subnet subnet_id] [--availability-zone zone] [--kernel kernel] [--ramdisk ramdisk] [--block-device-mapping mapping] [--monitor] [--iam-profile arn | name] [--network-interface NETWORKINTERFACE] [[--secondary-private-ip-address IP_ADDRESS] | [--secondary-private-ip-address-count COUNT]] [--ebs-optimized Boolean]

Options

NameDescription

ami_id

The ID of the AMI.

Type: String

Default: None

Required: Yes

Example: ami-2bb65342

-p, --price price

The maximum hourly price for any Spot Instance launched to fulfill the request.

Type: String

Default: None

Required: Yes

Example: -p .15

-n, --instance-count count

The maximum number of Spot Instances to launch.

Type: xs:integer

Default: 1

Required: No

Example: -n 10

-r, --type type

The Spot Instance request type.

Type: String

Valid values: one-time | persistent

Default: one-time

Required: No

Example: -r persistent

-s, --subnet subnet_id

The ID of the subnet in which to launch the Spot Instance.

Type: String

Default: None

Required: No

Example: -s subnet-baab943d3

--valid-from date

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.

Type: DateTime

Default: Request is effective indefinitely.

Required: No

Example: --valid-from 2009-12-31T11:51:50

--valid-until date

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.

Type: DateTime

Default: Request is effective indefinitely.

Required: No

Example: --valid-until 2009-12-31T11:51:50

--launch-group group

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

Type: String

Default: Instances are launched and terminated individually.

Required: No

Example: --launch-group Skynet

--availability-zone-group group

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

When you specify --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 choice of Availability Zone is not. --availability-zone-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 will be 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 (for example, all instances are terminated, the bid is expired, or the bid falls below current market), then Amazon EC2 will launch 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 the same --availability-zone-group name was specified.

To ensure that all Spot Instances across all bids are launched into a particular Availability Zone, specify LaunchSpecification.Placement.AvailabilityZone in the API or --availability-zone in the CLI.

Type: String

Default: Instances are launched in any available Availability Zone.

Required: No

Example: --availability-zone-group batchGroup01

--placement-group group_name

The name of an existing placement group you want to launch the instance into (for cluster instances).

Type: String

Default: Instances are launched in the default placement group.

Required: No

Example: --placement-group default

-d, --user-data user_data

The user data to make available to the instances.

Type: String

Default: None

Required: No

Example: -d "My user data"

-g, --group group

The ID of the security group.

Type: String

Default: User's default group.

Required: No

Example: -g MySecurityGroupID

-k, --key key_name

The name of the key pair.

Type: String

Default: None

Required: No

Example: -k gsg-keypair

-t, --instance-type instance_type

The instance type.

Type: String

Valid values: t1.micro | m1.small | m1.medium | m1.large | m1.xlarge | m3.xlarge | m3.2xlarge | c1.medium | c1.xlarge | m2.xlarge | m2.2xlarge | m2.4xlarge | cr1.8xlarge | cc1.4xlarge | cc2.8xlarge | cg1.4xlarge. See Available Instance Types for more information.

Default: m1.small

Required: No

Example: -t m1.large

-z, --availability-zone zone

The placement constraint (for example, a specific Availability Zone) for launching the instances.

Specify whether you want all of the Spot Instances in all of your bids to be launched in a particular Availability Zone. Specifying this option requires Amazon EC2 to find capacity in the specified Availability Zone instead of letting Amazon EC2 pick the best Availability Zone available; this can potentially delay the fulfillment of your bid, and/or require a higher bid price.

Type: String

Default: Amazon EC2 selects an Availability Zone in the current region.

Required: No

Example: -z us-east-1b

--kernel kernel

The ID of the kernel to select.

Type: String

Default: None

Required: No

Example: --kernel aki-ba3adfd3

--ramdisk ramdisk

The ID of the RAM disk to select.

Important

We recommend that you use PV-GRUB instead of kernels and RAM disks. For more information, see PV-GRUB: A New Amazon Kernel Image in the Amazon Elastic Compute Cloud User Guide.

Type: String

Default: None

Required: No

Example: --ramdisk ari-badbad00

-b, --block-device-mapping mapping

The block device mapping for the instance. This argument is passed in the form of <devicename>=<blockdevice>. The devicename is the name of the device within Amazon EC2. The blockdevice can be one of the following values:

  • none - Suppresses an existing mapping of the device from the AMI used to launch the instance. For example: "/dev/sdc=none".

  • ephemeral[0..3] - An instance store volume to be mapped to the device. For example: "/dev/sdc=ephemeral0".

  • [snapshot-id]:[volume-size]:[true|false]:[standard|io1[:iops]] - An EBS volume to be mapped to the device. [snapshot-id] To create a volume from a snapshot, specify the snapshot ID. [volume-size] To create an empty EBS volume, omit the snapshot ID and specify a volume size instead. For example: "/dev/sdh=:20". [delete-on-termination] To prevent the volume from being deleted on termination of the instance, specify false. The default is true. [volume-type] To create a Provisioned IOPS volume, specify io1. The default volume type is standard. If the volume type is io1, you can also provision the number of IOPS that the volume supports. For example, "/dev/sdh=snap-7eb96d16::false:io1:500".

You can specify multiple block-device-mapping arguments in one call.

For more detailed information about block device mapping, see Block Device Mapping in the Amazon Elastic Compute Cloud User Guide.

Type: String

Default: None

Required: No

Example: -b "/dev/sdb=snap-92d333fb::false"

Note

On Windows, the mapping argument must be enclosed in double quotes, as shown in the example.

--monitor

Enables monitoring for the instance.

Type: String

Default: Disabled

Required: No

Example: --monitor

--iam-profile arn|name

The IAM instance profile to associate with the launched instances. IAM instance profiles enable you to manage permissions for applications running on EC2. This is either the Amazon Resource Name (ARN) of the instance profile (for example, arn:aws:iam::111111111111:instance-profile/s3access) or the name of the role (for example, s3access).

Type: String

Default: None

Required: No

Example: arn:aws:iam::111111111111:instance-profile/s3access

-a, --network-interface NETWORKINTERFACE

[EC2-VPC] The network attachment for the launched instance. The format of the NETWORKINTERFACE definition is as follows:

For an existing NETWORKINTERFACE - eni :dev index

For a new NETWORKINTERFACE - dev index : subnet [: description [":<priv IP>"[:<SGs>[:<DOT>

[:SIP count[:"<SIPs>"]]]]]]], where SGs is a comma separated list of security group IDs, DOT is either true or false, denoting whether to delete the interface on terminate, SIP count is the number of secondary IP addresses to assign, SIPs is a list of secondary IP addresses. You cannot specify both SIP count and SIPs.

Type: String

Default: None

Required: No

--secondary-private-ip-address IP_ADDRESS

Assigns the specified IP address as a secondary private IP address to the network interface or instance. This option can be used multiple times to assign multiple secondary IP addresses. This option is only available for instances running in a VPC. You cannot specify this parameter when also specifying --secondary-private-ip-address-count.

You can do one of the following:

  • Use the --secondary-private-ip-address option without a value and AWS will automatically assign a secondary private IP address within the subnet range.

  • Use the --secondary-private-ip-address option and provide a specific IP address that you want to assign.

Note

On Windows clients, you must enclose IP addresses in quotes.

Type: String

Default: None

Required: No

Example: --secondary-private-ip-address "10.0.2.18" --secondary-private-ip-address "10.0.2.28"

--secondary-private-ip-address-count COUNT

The number of secondary IP addresses to assign to the network interface or instance. You cannot specify this parameter when also specifying --secondary-private-ip-address. This option is only available for instances running in a VPC.

Type: Integer

Default: None

Required: No

Example: --secondary-private-ip-address-count 2

--ebs-optimized Boolean

Whether the instance is optimized for EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal EBS I/O performance. This option isn't available on all instance types. Additional usage charge apply when using this option.

Type: Boolean

Default: false

Required: No

Example: --ebs-optimized true

Common Options

OptionDescription

--region REGION

Overrides the region specified by the EC2_URL environment variable and the URL specified by the -U option.

Default: The value of the EC2_URL environment variable, or us-east-1 if EC2_URL isn't set.

Example: --region eu-west-1

-U, --url URL

The uniform resource locator (URL) of the Amazon EC2 web service entry point.

Default: The value of the EC2_URL environment variable, or https://ec2.amazonaws.com if EC2_URL isn't set.

Example: -U https://ec2.amazonaws.com

-O, --aws-access-key AWS_ACCESS_KEY

The access key ID associated with your AWS account. For more information, see Tell the Tools Who You Are.

Default: The value of the AWS_ACCESS_KEY environment variable. If AWS_ACCESS_KEY isn't set, you must specify this option.

Example: -O AKIAIOSFODNN7EXAMPLE

Note

For more information, see the following section, Deprecated Options.

-W, --aws-secret-key AWS_SECRET_KEY

The secret access key associated with your AWS account.

Default: The value of the AWS_SECRET_KEY environment variable. If AWS_SECRET_KEY isn't set, you must specify this option.

Example: -W wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Note

For more information, see the following section, Deprecated Options.

-T, --security-token TOKEN AWS_DELEGATION_TOKEN

The AWS delegation token.

Default: The value of the environment variable (if set).

--connection-timeout TIMEOUT

The connection timeout, in seconds.

Example: --connection-timeout 30

--request-timeout TIMEOUT

The request timeout, in seconds.

Example: --request-timeout 45

-v, --verbose

Displays verbose output, including the API request and response on the command line. This is useful if you are building tools to talk directly to our Query API.

-H, --headers

Includes column headers in the command output.

--show-empty-fields

Shows empty columns as (nil).

--hide-tags

Omits tags for tagged resources.

--debug

Displays internal debugging information. This can assist us when helping you troubleshooting problems.

-?, --help, -h

Displays usage information for the command.

-

Reads arguments from standard input. This is useful when piping the output from one command to the input of another.

Example: ec2-describe-instances | grep stopped | cut -f 2 | ec2-start-instances -

Deprecated Options

For a limited time, you can still use the private key and X.509 certificate instead of your access key ID and secret access key. However, we recommend that you start using your access key ID (-O, --aws-access-key) and secret access key (-W, --aws-secret-key) now, as the private key (-K, --private-key) and X.509 certificate (-C, --cert) won't be supported after the transition period elapses. For more information, see Tell the Tools Who You Are.

OptionDescription

-K, --private-key EC2-PRIVATE-KEY

The private key to use when constructing requests to Amazon EC2.

Default: The value of the EC2_PRIVATE_KEY environment variable.

Example: -K pk-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem

-C, --cert EC2-CERT

The X.509 certificate to use when constructing requests to Amazon EC2.

Default: The value of the EC2_CERT environment variable.

Example: -C cert-HKZYKTAIG2ECMXYIBH3HXV4ZBEXAMPLE.pem

Output

This command returns a table that contains the following information for each Spot Instance request:

The Spot Instance request information

  • The SPOTINSTANCEREQUEST identifier

  • The ID of the Spot Instance request

  • The Spot Instance bid price

  • The Spot Instance type (one-time or persistent)

  • The product description (Linux/UNIX or Windows)

  • The state of the Spot Instance request (active, open, closed, cancelled, failed)

  • The date and time the request was created

  • The date and time that the request is valid until

  • The date and time the request will be held until

  • The launch group

  • The Availability Zone group

  • The instance ID

  • The image ID

  • The instance type

  • The key pair name

  • Any security groups the request belongs to

  • The Availability Zone the instance belongs to

  • The kernel ID of the instance

  • The RAM disk ID of the instance

  • The monitoring status

  • The subnet ID

  • The Availability Zone the instance was launched to

  • The IAM profile

Any Spot Instance faults

  • The SPOTINSTANCEFAULT identifier

  • The Spot Instance fault code

  • The Spot Instance fault message

The Spot Instance status information

  • The SPOTINSTANCESTATUS identifier

  • The Spot Instance status

  • The date and time of the last update

  • The Spot Instance status message

Amazon EC2 command line tools display errors on stderr.

Examples

Example Request

This example creates a Spot Instances request for three m1.small instances.

PROMPT>  ec2-request-spot-instances ami-1a2b3c4d -p 0.04 --key gsg-keypair --group default --instance-type m1.small -n 3 --type one-time
SPOTINSTANCEREQUEST	sir-1a2b3c4d	0.040000	one-time	Linux/UNIX	open	YYYY-MM-DDTHH:MM:SS-0800						ami-1a2b3c4d	m1.small	gsg-keypair	sg-1a2b3c4d				monitoring-disabled			
SPOTINSTANCESTATUS	pending-evaluation	YYYY-MM-DDTHH:MM:SS-0800	Your Spot request has been submitted for review, and is pending evaluation.
SPOTINSTANCEREQUEST	sir-2a2b3c4d	0.040000	one-time	Linux/UNIX	open	YYYY-MM-DDTHH:MM:SS-0800						ami-1a2b3c4d	m1.small	gsg-keypair	sg-1a2b3c4d				monitoring-disabled			
SPOTINSTANCESTATUS	pending-evaluation	YYYY-MM-DDTHH:MM:SS-0800	Your Spot request has been submitted for review, and is pending evaluation.
SPOTINSTANCEREQUEST	sir-3a2b3c4d	0.040000	one-time	Linux/UNIX	open	YYYY-MM-DDTHH:MM:SS-0800						ami-1a2b3c4d	m1.small	gsg-keypair	sg-1a2b3c4d				monitoring-disabled			
SPOTINSTANCESTATUS	pending-evaluation	YYYY-MM-DDTHH:MM:SS-0800	Your Spot request has been submitted for review, and is pending evaluation.