RunInstances

The RunInstances operation launches a specified number of instances.

[Note]Note

The Query version of RunInstances only allows instances of a single AMI to be launched in one call. This is different from the SOAP API version of the call, but similar to the ec2-run-instances command line tool.

If Amazon EC2 cannot launch the minimum number AMIs you request, no instances launch. If there is insufficient capacity to launch the maximum number of AMIs you request, Amazon EC2 launches as many as possible to satisfy the requested maximum values.

Every instance is launched in a security group. If you do not specify a security group at launch, the instances start in your default security group. For more information on creating security groups, see CreateSecurityGroup.

An optional instance type can be specified. For information about instance types, see Instance Types.

You can provide an optional key pair ID for each image in the launch request (for more information, see CreateKeyPair). 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]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 ephemeral 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, see Instance Metadata.

[Note]Note

If any of the AMIs have a product code attached for which the user has not subscribed, the RunInstances call will fail.

[Important]Important

We strongly recommend using the 2.6.18 Xen stock kernel with the c1.medium and c1.xlarge 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, see Kernels, RAM Disks, and Block Device Mappings.

The following table describes the request parameters for RunInstances. Parameter names are case sensitive.

NameDescriptionRequired

ImageId

ID of the AMI with which to launch instances.

Type: String

Yes

MinCount

Minimum number of instances to launch.

Type: Int

Yes

MaxCount

Maximum number of instances to launch.

Type: Int

Yes

KeyName

Name of the key pair with which to launch instances.

Type: String

No

SecurityGroup.n

Names of the security groups with which to associate the instances.

Type: String

No

UserData

The user data available to the launched instances. This should be Base64 encoded. For more information on encoding details, see UserDataType.

Type: String

No

InstanceType

Specifies the instance type.

Options include m1.small, m1.large, m1.xlarge, c1.medium, and c1.xlarge.

The default value is m1.small.

For more information on instance types, see Instance Types.

Type: xsd:string

No

Placement.AvailabilityZone

Specifies the availability zone in which to launch the instance(s).

To display a list of availability zones in which you can launch the instances, use the DescribeAvailabilityZones operation. For more information, see DescribeAvailabilityZones.

For more information on instance types, see Availability Zones.

Type: xsd:string

By default, Amazon EC2 selects an availability zone for you.

No

KernelId

The ID of the kernel with which to launch the instance. For information on finding available kernel IDs, see ec2-describe-images.

Example: aki-ba3adfd3

No

RamdiskId

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.

Example: ari-badbad00

No

BlockDeviceMapping.

n.VirtualName

Specifies the virtual name to map to the corresponding device name. For example: ephemeral0

This parameter must be used in conjunction with BlockDeviceMapping.n.DeviceName.

No

BlockDeviceMapping.

n.DeviceName

Specifies the device to which you are mapping a virtual name. For example: sdb

This parameter must be used in conjunction with BlockDeviceMapping.n.VirtualName.

No

The following table describes the default response tags included in RunInstances responses.

NameDescription

RunInstancesResponse

Status information about the instances launched.

Type: ReservationInfoType

https://ec2.amazonaws.com/

?Action=RunInstances

&ImageId=ami-60a54009

&MaxCount=3

&MinCount=1

&AddressingType=public

&Placement.AvailabilityZone=us-east-1b

&...auth parameters...


<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-02-01">

  <reservationId>r-47a5402e</reservationId>

  <ownerId>495219933132</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>      

    </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>            

    </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>      

    </item>

  </instancesSet>

</RunInstancesResponse>