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

RunInstances

Launches the specified number of instances using an AMI for which you have permissions.

You can specify a number of options, or leave the default options. The following rules apply:

  • [EC2-VPC] If you don't specify a subnet ID, we choose a default subnet from your default VPC for you. If you don't have a default VPC, you must specify a subnet ID in the request.

  • [EC2-Classic] If don't specify an Availability Zone, we choose one for you.

  • Some instance types must be launched into a VPC. If you do not have a default VPC, or if you do not specify a subnet ID, the request fails. For more information, see Instance Types Available Only in a VPC.

  • [EC2-VPC] All instances have a network interface with a primary private IPv4 address. If you don't specify this address, we choose one from the IPv4 range of your subnet.

  • Not all instance types support IPv6 addresses. For more information, see Instance Types.

  • If you don't specify a security group ID, we use the default security group. For more information, see Security Groups.

  • If any of the AMIs have a product code attached for which the user has not subscribed, the request fails.

You can create a launch template, which is a resource that contains the parameters to launch an instance. When you launch an instance using RunInstances, you can specify the launch template instead of specifying the launch parameters.

To ensure faster instance launches, break up large requests into smaller batches. For example, create five separate launch requests for 100 instances each instead of one launch request for 500 instances.

An instance is ready for you to use when it's in the running state. You can check the state of your instance using DescribeInstances. You can tag instances and EBS volumes during launch, after launch, or both. For more information, see CreateTags and Tagging Your Amazon EC2 Resources.

Linux instances have access to the public key of the key pair at boot. You can use this key to provide secure access to the instance. Amazon EC2 public images use this feature to provide secure access without passwords. For more information, see Key Pairs in the Amazon Elastic Compute Cloud User Guide.

For troubleshooting, see What To Do If An Instance Immediately Terminates, and Troubleshooting Connecting to Your Instance 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.

AdditionalInfo

Reserved.

Type: String

Required: No

BlockDeviceMapping.N

One or more block device mapping entries. You can't specify both a snapshot ID and an encryption value. This is because only blank volumes can be encrypted on creation. If a snapshot is the basis for a volume, it is not blank and its encryption status is used for the volume encryption status.

Type: Array of BlockDeviceMapping objects

Required: No

ClientToken

Unique, case-sensitive identifier you provide to ensure the idempotency of the request. For more information, see Ensuring Idempotency.

Constraints: Maximum 64 ASCII characters

Type: String

Required: No

CreditSpecification

The credit option for CPU usage of the instance. Valid values are standard and unlimited. To change this attribute after launch, use ModifyInstanceCreditSpecification. For more information, see T2 Instances in the Amazon Elastic Compute Cloud User Guide.

Default: standard

Type: CreditSpecificationRequest object

Required: No

DisableApiTermination

If you set this parameter to true, you can't terminate the instance using the Amazon EC2 console, CLI, or API; otherwise, you can. To change this attribute to false after launch, use ModifyInstanceAttribute. Alternatively, if you set InstanceInitiatedShutdownBehavior to terminate, you can terminate the instance by running the shutdown command from the instance.

Default: false

Type: Boolean

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

EbsOptimized

Indicates whether the instance is optimized for Amazon EBS I/O. This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS-optimized instance.

Default: false

Type: Boolean

Required: No

ElasticGpuSpecification.N

An elastic GPU to associate with the instance.

Type: Array of ElasticGpuSpecification objects

Required: No

IamInstanceProfile

The IAM instance profile.

Type: IamInstanceProfileSpecification object

Required: No

ImageId

The ID of the AMI, which you can get by calling DescribeImages.

Type: String

Required: No

InstanceInitiatedShutdownBehavior

Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

Default: stop

Type: String

Valid Values: stop | terminate

Required: No

InstanceMarketOptions

The market (purchasing) option for the instances.

Type: InstanceMarketOptionsRequest object

Required: No

InstanceType

The instance type. For more information, see Instance Types in the Amazon Elastic Compute Cloud User Guide.

Default: m1.small

Type: String

Valid Values: t1.micro | t2.nano | t2.micro | t2.small | t2.medium | t2.large | t2.xlarge | t2.2xlarge | m1.small | m1.medium | m1.large | m1.xlarge | m3.medium | m3.large | m3.xlarge | m3.2xlarge | m4.large | m4.xlarge | m4.2xlarge | m4.4xlarge | m4.10xlarge | m4.16xlarge | m2.xlarge | m2.2xlarge | m2.4xlarge | cr1.8xlarge | r3.large | r3.xlarge | r3.2xlarge | r3.4xlarge | r3.8xlarge | r4.large | r4.xlarge | r4.2xlarge | r4.4xlarge | r4.8xlarge | r4.16xlarge | x1.16xlarge | x1.32xlarge | x1e.xlarge | x1e.2xlarge | x1e.4xlarge | x1e.8xlarge | x1e.16xlarge | x1e.32xlarge | i2.xlarge | i2.2xlarge | i2.4xlarge | i2.8xlarge | i3.large | i3.xlarge | i3.2xlarge | i3.4xlarge | i3.8xlarge | i3.16xlarge | hi1.4xlarge | hs1.8xlarge | c1.medium | c1.xlarge | c3.large | c3.xlarge | c3.2xlarge | c3.4xlarge | c3.8xlarge | c4.large | c4.xlarge | c4.2xlarge | c4.4xlarge | c4.8xlarge | c5.large | c5.xlarge | c5.2xlarge | c5.4xlarge | c5.9xlarge | c5.18xlarge | cc1.4xlarge | cc2.8xlarge | g2.2xlarge | g2.8xlarge | g3.4xlarge | g3.8xlarge | g3.16xlarge | cg1.4xlarge | p2.xlarge | p2.8xlarge | p2.16xlarge | p3.2xlarge | p3.8xlarge | p3.16xlarge | d2.xlarge | d2.2xlarge | d2.4xlarge | d2.8xlarge | f1.2xlarge | f1.16xlarge | m5.large | m5.xlarge | m5.2xlarge | m5.4xlarge | m5.12xlarge | m5.24xlarge | h1.2xlarge | h1.4xlarge | h1.8xlarge | h1.16xlarge

Required: No

Ipv6Address.N

[EC2-VPC] Specify one or more IPv6 addresses from the range of the subnet to associate with the primary network interface. You cannot specify this option and the option to assign a number of IPv6 addresses in the same request. You cannot specify this option if you've specified a minimum number of instances to launch.

Type: Array of InstanceIpv6Address objects

Required: No

Ipv6AddressCount

[EC2-VPC] A number of IPv6 addresses to associate with the primary network interface. Amazon EC2 chooses the IPv6 addresses from the range of your subnet. You cannot specify this option and the option to assign specific IPv6 addresses in the same request. You can specify this option if you've specified a minimum number of instances to launch.

Type: Integer

Required: No

KernelId

The ID of the kernel.

Important

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

Type: String

Required: No

KeyName

The name of the key pair. You can create a key pair using CreateKeyPair or ImportKeyPair.

Important

If you do not specify a key pair, you can't connect to the instance unless you choose an AMI that is configured to allow users another way to log in.

Type: String

Required: No

LaunchTemplate

The launch template to use to launch the instances. Any parameters that you specify in RunInstances override the same parameters in the launch template.

Type: LaunchTemplateSpecification object

Required: No

MaxCount

The maximum number of instances to launch. If you specify more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches the largest possible number of instances above MinCount.

Constraints: Between 1 and the maximum number you're allowed for the specified instance type. For more information about the default limits, and how to request an increase, see How many instances can I run in Amazon EC2 in the Amazon EC2 FAQ.

Type: Integer

Required: Yes

MinCount

The minimum number of instances to launch. If you specify a minimum that is more instances than Amazon EC2 can launch in the target Availability Zone, Amazon EC2 launches no instances.

Constraints: Between 1 and the maximum number you're allowed for the specified instance type. For more information about the default limits, and how to request an increase, see How many instances can I run in Amazon EC2 in the Amazon EC2 General FAQ.

Type: Integer

Required: Yes

Monitoring

The monitoring for the instance.

Type: RunInstancesMonitoringEnabled object

Required: No

NetworkInterface.N

One or more network interfaces.

Type: Array of InstanceNetworkInterfaceSpecification objects

Required: No

Placement

The placement for the instance.

Type: Placement object

Required: No

PrivateIpAddress

[EC2-VPC] The primary IPv4 address. You must specify a value from the IPv4 address range of the subnet.

Only one private IP address can be designated as primary. You can't specify this option if you've specified the option to designate a private IP address as the primary IP address in a network interface specification. You cannot specify this option if you're launching more than one instance in the request.

Type: String

Required: No

RamdiskId

The ID of the RAM disk.

Important

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

Type: String

Required: No

SecurityGroup.N

[EC2-Classic, default VPC] One or more security group names. For a nondefault VPC, you must use security group IDs instead.

Default: Amazon EC2 uses the default security group.

Type: Array of strings

Required: No

SecurityGroupId.N

One or more security group IDs. You can create a security group using CreateSecurityGroup.

Default: Amazon EC2 uses the default security group.

Type: Array of strings

Required: No

SubnetId

[EC2-VPC] The ID of the subnet to launch the instance into.

Type: String

Required: No

TagSpecification.N

The tags to apply to the resources during launch. You can tag instances and volumes. The specified tags are applied to all instances or volumes that are created during launch.

Type: Array of TagSpecification objects

Required: No

UserData

The user data to make available to the instance. For more information, see Running Commands on Your Linux Instance at Launch (Linux) and Adding User Data (Windows). If you are using a command line tool, base64-encoding is performed for you, and you can load the text from a file. Otherwise, you must provide base64-encoded text.

Type: String

Required: No

Response Elements

The following elements are returned by the service.

groupSet

[EC2-Classic only] One or more security groups.

Type: Array of GroupIdentifier objects

instancesSet

One or more instances.

Type: Array of Instance objects

ownerId

The ID of the AWS account that owns the reservation.

Type: String

requesterId

The ID of the requester that launched the instances on your behalf (for example, AWS Management Console or Auto Scaling).

Type: String

requestId

The ID of the request.

Type: String

reservationId

The ID of the reservation.

Type: String

Errors

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

Examples

Example 1

This example launches three instances using the AMI with the ID ami-60a54009.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-60a54009
&MaxCount=3
&MinCount=1
&KeyName=my-key-pair
&Placement.AvailabilityZone=us-east-1d
&AUTHPARAMS

Example 2

This example launches an m1.small instance into a subnet. Because no network interface is specified, a new network interface is created.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-31814f58
&InstanceType=m1.small
&MaxCount=1
&MinCount=1
&KeyName=my-key-pair
&SubnetId=subnet-b2a249da
&AUTHPARAMS

Example 3

This example launches an m1.large instance into a subnet. The network interface specifies a primary private IPv4 address of 10.0.2.106 and two secondary private IPv4 addresses (10.0.2.107 and 10.0.2.108).

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-beb0caec
&InstanceType=m1.large
&MaxCount=1
&MinCount=1
&KeyName=my-key-pair
&NetworkInterface.1.DeviceIndex=0
&NetworkInterface.1.PrivateIpAddresses.1.Primary=true
&NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress=10.0.2.106
&NetworkInterface.1.PrivateIpAddresses.2.Primary=false
&NetworkInterface.1.PrivateIpAddresses.2.PrivateIpAddress=10.0.2.107
&NetworkInterface.1.PrivateIpAddresses.3.Primary=false
&NetworkInterface.1.PrivateIpAddresses.3.PrivateIpAddress=10.0.2.108
&NetworkInterface.1.SubnetId=subnet-a61dafcf
&AUTHPARAMS

Example 4

This example launches a Dedicated Instance into the specified subnet.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-2a1fec43
&MaxCount=1
&MinCount=1
&KeyName=my-key-pair
&SubnetId=subnet-dea63cb7
&Placement.Tenancy=dedicated
&AUTHPARAMS

Example 5

This request launches an instance into a nondefault subnet, and requests a public IPv4 address for a new network interface with the device index of 0.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-1a2b3c4d
&MaxCount=1
&MinCount=1
&NetworkInterface.1.DeviceIndex=0
&NetworkInterface.1.AssociatePublicIpAddress=true
&NetworkInterface.1.SubnetId=subnet-1a2b3c4d
&AUTHPARAMS

Example 6

This request launches an m1.large instance with a block device mapping. There are two instance store volumes mapped to /dev/sdc and /dev/sdd, and a 100-GB EBS volume mapped to /dev/sdf. The EBS volume attached to the instance will be encrypted under a customer-managed CMK.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-1a2b3c4d
&InstanceType=m1.large
&BlockDeviceMapping.1.DeviceName=%2Fdev%2Fsdc
&BlockDeviceMapping.1.VirtualName=ephemeral0
&BlockDeviceMapping.2.DeviceName=%2Fdev%2Fsdd
&BlockDeviceMapping.2.VirtualName=ephemeral1
&BlockDeviceMapping.3.DeviceName=%2Fdev%2Fsdf
&BlockDeviceMapping.3.Ebs.DeleteOnTermination=false
&BlockDeviceMapping.3.Ebs.VolumeSize=100
&BlockDeviceMapping.3.Ebs.Encrypted=true 
&BlockDeviceMapping.3.Ebs.KmsKeyId=arn%3Aaws%3Akms%3Aus-east-1%3A009400881653%3Akey%2Fa48a521f-3aff-4b34-a159-376ac5d37812
&EbsOptimized=false
&MinCount=1
&MaxCount=1
&DisableApiTermination=false
&Monitoring.Enabled=false
&AUTHPARAMS

Example 7

This request launches two instances and applies a tag with a key of webserver and a value of production to the instances. The request also applies a tag with a key of cost-center and a value of cc123 to the volumes that are created (in this case, the root volume for each instance).

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-31814f58
&InstanceType=t2.large
&MaxCount=2
&MinCount=1
&KeyName=my-key-pair
&SubnetId=subnet-b2a249da
&TagSpecification.1.ResourceType=instance
&TagSpecification.1.Tag.1.Key=webserver
&TagSpecification.1.Tag.1.Value=production
&TagSpecification.2.ResourceType=volume
&TagSpecification.2.Tag.1.Key=cost-center
&TagSpecification.2.Tag.1.Value=cc123
&AUTHPARAMS

Example 8

This request launches a t2.micro instance with the credit option for CPU usage set to unlimited.

Sample Request

https://ec2.amazonaws.com/?Action=RunInstances
&ImageId=ami-31814f58
&Count=1
&InstanceType=t2.micro
&KeyName=my-key-pair
&CreditSpecification.CpuCredits=unlimited
&AUTHPARAMS

See Also

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