RunInstances
Description
Launches a specified number of instances of an AMI for which you have permissions.
If Amazon EC2 cannot launch the minimum number AMIs you request, no instances will be launched. If there is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches the minimum number specified for each AMI and allocate the remaining available instances using round robin.
In the following example, Libby generates a request to launch two images (database and web_server):
Libby runs the
RunInstances
operation to launch database instances (min. 10, max. 15) and web_server instances (min. 30, max. 40).Because there are currently 30 instances available and Libby needs a minimum of 40, no instances are launched.
Libby adjusts the number of instances she needs and runs the
RunInstances
operation to launch database instances (min. 5, max. 10) and web_server instances (min. 20, max. 40).Amazon EC2 launches the minimum number of instances for each AMI (5 database, 20 web_server).
The remaining 5 instances are allocated using round robin.
Libby adjusts the number of instances she needs and runs the
RunInstances
operation again to launch database instances (min. 5, max. 10) and web_server instances (min. 20, max. 40).
Note | |
---|---|
Every instance is launched in a security group (created using the |
You can provide an optional key pair ID for each image in the launch request (created using the CreateKeyPair
operation). All instances that are created from images that use this key pair will have access to the associated public key at boot. You can use this key to provide secure access to an instance of an image on a per-instance basis. Amazon EC2 public images use this feature to provide secure access without passwords.
Important | |
---|---|
Launching public images without a key pair ID will leave them inaccessible. |
The public key material is made available to the instance at boot time by placing it in the openssh_id.pub
file on a logical device that is exposed to the instance as /dev/sda2
(the instance store). The format of this file is suitable for use as an entry within ~/.ssh/authorized_keys
(the OpenSSH format). This can be done at boot (e.g., as part of rc.local
) allowing for secure access without passwords.
Optional user data can be provided in the launch request. All instances that collectively comprise the launch request have access to this data. For more information, go the
Note | |
---|---|
If any of the AMIs have a product code attached for which the user has not subscribed, the |
Important | |
---|---|
We strongly recommend using the 2.6.18 Xen stock kernel with High-CPU and High-Memory instances. Although the default Amazon EC2 kernels will work, the new kernels provide greater stability and performance for these instance types. For more information about kernels, go the Amazon Elastic Compute Cloud Developer Guide. |
Request Parameters
Name | Description | Required |
---|---|---|
|
Type: RunInstancesType Ancestor: None Children: |
|
|
Unique ID of a machine image, returned by a call to Type: xsd:string Default: None Ancestor: Children: None |
Yes |
|
Minimum number of instances to launch. If the value is more than Amazon EC2 can launch, no instances are launched at all. Type: xsd:int Default: None Constraints: Between 1 and the maximum number allowed for your account (default: 20). Ancestor: Children: None |
Yes |
|
Maximum number of instances to launch. If the value is more than Amazon EC2 can launch, the largest possible number above minCount will be launched instead. Type: xsd:int Default: None Constraints: Between 1 and the maximum number allowed for your account (default: 20). Ancestor: Children: None |
Yes |
|
The name of the key pair. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Group set. Type: GroupSetType Ancestor: Children: |
|
|
Group set item. Type: GroupItemType Ancestor: Children: |
|
|
Name of the security group. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies additional information to make available to the instance(s). Type: xsd:string Default: None Ancestor: Children: None |
No |
|
MIME, Base64-encoded user data. Type: UserDataType Ancestor: Children: |
|
|
MIME, Base64-encoded user data. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Deprecated. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies the instance type. Type: xsd:string Valid Values: Default: m1.small Ancestor: Children: None |
No |
|
Placement item. Type: PlacementRequestType Ancestor: Children: |
No |
|
Specifies the placement constraints (Availability Zones) for launching the instances. Type: xsd:string Default: Amazon EC2 selects an Availability Zone. Ancestor: Children: None |
No |
|
The ID of the kernel with which to launch the instance. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
The ID of the RAM disk with which to launch the instance. Some kernels require additional drivers at launch. Check the kernel requirements for information on whether you need to specify a RAM disk. To find kernel requirements, go to the Resource Center and search for the kernel ID. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies how block devices are exposed to the instance. Each mapping is made up of a virtualName and a deviceName. Type: BlockDeviceMappingType Ancestor: Children: |
No |
|
Information for one block device mapping. Type: BlockDeviceMappingItemType Ancestor: Children: |
|
|
The device name (e.g., /dev/sdh). Type: xsd:string Default: None Ancestor: Children: None |
No |
|
The virtual device name. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies parameters used to automatically setup Amazon EBS volumes when the instance is launched. Type: EbsBlockDeviceType Ancestor: Children: |
Yes |
|
The ID of the snapshot. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
The size of the volume. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies whether the Amazon EBS volume is deleted on instance termination. Type: xsd:boolean Default: true Ancestor: Children: None |
No |
|
Specifies the device name to suppress during instance launch. Type: EmptyElementType Ancestor: Children: |
No |
|
This element contains no options. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies whether to enable monitoring for the instance. Type: MonitoringInstanceType Ancestor: Children: |
No |
|
Enables monitoring for the instance. Type: xsd:boolean Default: Disabled Ancestor: Children: None |
No |
|
Specifies the Amazon VPC subnet ID within which to launch the instance(s) for Amazon Virtual Private Cloud. Type: xsd:string Default: None Ancestor: Children: None |
No |
|
Specifies whether the instance can be terminated using the APIs. You must modify this attribute before you can terminate any "locked" instances from the APIs. Type: xsd:boolean Default: true Ancestor: Children: None |
No |
|
Specifies whether the instance's Amazon EBS volumes are stopped or terminated when the instance is shut down. Type: xsd:boolean Default: true Ancestor: Children: None |
No |
Response Elements
Name | Description |
---|---|
|
Type: RunInstancesResponseType Ancestor: None Children: |
|
The ID of the request. Type: xsd:string Ancestor: Children: None |
|
Unique ID of the reservation. Type: xsd:string Ancestor: Children: None |
|
AWS Access Key ID of the user who owns the reservation. Type: xsd:string Ancestor: Children: None |
|
Group set. Type: GroupSetType Ancestor: Children: |
|
Group set item. Type: GroupItemType Ancestor: Children: |
|
Name of the security group. Type: xsd:string Ancestor: Children: None |
|
Instance set. Type: RunningInstancesSetType Ancestor: Children: |
|
Running instance set item. Type: RunningInstancesItemType Ancestor: Children: |
|
Unique ID of the instance launched. Type: xsd:string Ancestor: Children: None |
|
Image ID of the AMI used to launch the instance. Type: xsd:string Ancestor: Children: None |
|
The current state of the instance. Type: InstanceStateType Ancestor: Children: |
|
A 16-bit unsigned integer. The high byte is an opaque internal value and should be ignored. The low byte is set based on the state represented: Type: xsd:int Valid Values: Ancestor: Children: None |
|
The current state of the instance. Type: xsd:string Valid Values: Ancestor: Children: None |
|
The private DNS name assigned to the instance. This DNS name can only be used inside the Amazon EC2 network. This element remains empty until the instance enters a running state. Type: xsd:string Ancestor: Children: None |
|
The public DNS name assigned to the instance. This DNS name is contactable from outside the Amazon EC2 network. This element remains empty until the instance enters a running state. Type: xsd:string Ancestor: Children: None |
|
Reason for the most recent state transition. This might be an empty string. Type: xsd:string Ancestor: Children: None |
|
If this instance was launched with an associated key pair, this displays the key pair name. Type: xsd:string Ancestor: Children: None |
|
The AMI launch index, which can be used to find this instance within the launch group. Type: xsd:string Ancestor: Children: None |
|
Product codes attached to this instance. Type: ProductCodesSetType Ancestor: Children: |
|
Information for one product code. Type: ProductCodesSetItemType Ancestor: Children: |
|
Product code. Type: xsd:string Ancestor: Children: None |
|
The instance type. Type: xsd:string Ancestor: Children: None |
|
The time the instance launched. Type: xsd:dateTime Ancestor: Children: None |
|
The location where the instance launched. Type: PlacementResponseType Ancestor: Children: |
|
Returns the Availability Zone of the instance. Type: xsd:string Ancestor: Children: None |
|
Kernel associated with this instance. Type: xsd:string Ancestor: Children: None |
|
RAM disk associated with this instance. Type: xsd:string Ancestor: Children: None |
|
Platform of the instance (e.g., Windows). Type: xsd:string Ancestor: Children: None |
|
Specifies whether monitoring is enabled for the instance. Type: InstanceMonitoringStateType Ancestor: Children: |
|
State of monitoring for the instance. Type: xsd:string Valid Values: Ancestor: Children: None |
|
Specifies the Amazon VPC subnet ID in which the instance is running. Type: xsd:string Ancestor: Children: None |
|
Specifies the Amazon VPC in which the instance is running. Type: xsd:string Ancestor: Children: None |
|
Specifies the private IP address that is assigned to the instance. Type: xsd:string Ancestor: Children: None |
|
Specifies the IP address of the instance. Type: xsd:string Ancestor: Children: None |
|
The reason for the state change. Type: StateReasonType Ancestor: Children: |
|
Reason code for the state change. Type: xsd:string Ancestor: Children: None |
|
Message for the state change. Type: xsd:string Ancestor: Children: None |
|
The architecture of the image. Type: xsd:string Valid Values: Ancestor: Children: None |
|
The root device type used by the AMI. The AMI can use an Amazon EBS or instance store root device. Type: xsd:string Valid Values: Ancestor: Children: None |
|
The root device name (e.g., /dev/sda1). Type: xsd:string Ancestor: Children: None |
|
Block device mapping set. Type: InstanceBlockDeviceMappingResponseType Ancestor: Children: |
|
The item element. Type: InstanceBlockDeviceMappingResponseItemType Ancestor: Children: |
|
Specifies how the device is exposed to the instance (e.g., /dev/sdh). Type: xsd:string Ancestor: Children: None |
|
Specifies parameters used to automatically setup Amazon EBS volumes when the instance is launched. Type: EbsInstanceBlockDeviceMappingResponseType Ancestor: Children: |
|
The ID of the Amazon EBS volume. Type: xsd:string Ancestor: Children: None |
|
Attachment state. Type: xsd:string Valid Values: Ancestor: Children: None |
|
Time stamp when the attachment initiated. Type: xsd:dateTime Ancestor: Children: None |
|
Specifies whether the Amazon EBS volume is deleted on instance termination. Type: xsd:boolean Ancestor: Children: None |
|
ID of the requester. Type: xsd:string Ancestor: Children: None |
Examples
Example Request
This example launches three instances of the ami-60a54009
AMI.
<RunInstances xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <imageId>ami-60a54009</imageId> <minCount>1</minCount> <maxCount>3</maxCount> <keyName>example-key-name</keyName> <groupSet/> <placement> <availabilityZone>us-east-1b</availabilityZone> </placement> <kernelId>aki-ba3adfd3</kernelId> <ramdiskId>ari-badbad00</ramdiskId> <blockDeviceMapping> <item> <virtualName>ami</virtualName> <deviceName>sda1<deviceName> </item> <item> <virtualName>root</virtualName> <deviceName>/dev/sda1</deviceName> </item> <item> <virtualName>instancestore0</virtualName> <deviceName>sdb</deviceName> </item> <item> <virtualName>instance1</virtualName> <deviceName>sdc</deviceName> </item> </blockDeviceMapping> <userData version="1.0" encoding="base64"><data>"VGhpcyBpcyBiYXNlIDY0IQ==</data></userData> <addressingType>public</addressingType> <monitoring>enabled</monitoring></RunInstances>
Example Response
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2009-10-31/"> <reservationId>r-47a5402e</reservationId> <ownerId>AIDADH4IGTRXXKCD</ownerId> <groupSet> <item> <groupId>default</groupId> </item> </groupSet> <instancesSet> <item> <instanceId>i-2ba64342</instanceId> <imageId>ami-60a54009</imageId> <instanceState> <code>0</code> <name>pending</name> </instanceState> <privateDnsName></privateDnsName> <dnsName></dnsName> <keyName>example-key-name</keyName> <amiLaunchIndex>0</amiLaunchIndex> <instanceType>m1.small</instanceType> <launchTime>2007-08-07T11:51:50.000Z</launchTime> <placement> <availabilityZone>us-east-1b</availabilityZone> </placement> <monitoring> <enabled>true</enabled> </monitoring> </item> <item> <instanceId>i-2bc64242</instanceId> <imageId>ami-60a54009</imageId> <instanceState> <code>0</code> <name>pending</name> </instanceState> <privateDnsName></privateDnsName> <dnsName></dnsName> <keyName>example-key-name</keyName> <amiLaunchIndex>1</amiLaunchIndex> <instanceType>m1.small</instanceType> <launchTime>2007-08-07T11:51:50.000Z</launchTime> <placement> <availabilityZone>us-east-1b</availabilityZone> </placement> <monitoring> <enabled>true</enabled> </monitoring> </item> <item> <instanceId>i-2be64332</instanceId> <imageId>ami-60a54009</imageId> <instanceState> <code>0</code> <name>pending</name> </instanceState> <privateDnsName></privateDnsName> <dnsName></dnsName> <keyName>example-key-name</keyName> <amiLaunchIndex>2</amiLaunchIndex> <instanceType>m1.small</instanceType> <launchTime>2007-08-07T11:51:50.000Z</launchTime> <placement> <availabilityZone>us-east-1b</availabilityZone> </placement> <monitoring> <enabled>true</enabled> </monitoring> </item> </instancesSet> </RunInstancesResponse>