AWS SDK Version 3 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

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:

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.

For troubleshooting, see What to do if an instance immediately terminates, and Troubleshooting connecting to your instance.

Note:

For .NET Core this operation is only available in asynchronous form. Please refer to RunInstancesAsync.

Namespace: Amazon.EC2
Assembly: AWSSDK.EC2.dll
Version: 3.x.y.z

Syntax

C#
public virtual RunInstancesResponse RunInstances(
         RunInstancesRequest request
)

Parameters

request
Type: Amazon.EC2.Model.RunInstancesRequest

Container for the necessary parameters to execute the RunInstances service method.

Return Value


The response from the RunInstances service method, as returned by EC2.

Examples

This example launches an instance using the specified AMI, instance type, security group, subnet, block device mapping, and tags.

To launch an instance


var client = new AmazonEC2Client();
var response = client.RunInstances(new RunInstancesRequest 
{
    BlockDeviceMappings = new List<BlockDeviceMapping> {
        new BlockDeviceMapping {
            DeviceName = "/dev/sdh",
            Ebs = new EbsBlockDevice { VolumeSize = 100 }
        }
    },
    ImageId = "ami-abc12345",
    InstanceType = "t2.micro",
    KeyName = "my-key-pair",
    MaxCount = 1,
    MinCount = 1,
    SecurityGroupIds = new List<string> {
        "sg-1a2b3c4d"
    },
    SubnetId = "subnet-6e7f829e",
    TagSpecifications = new List<TagSpecification> {
        new TagSpecification {
            ResourceType = "instance",
            Tags = new List<Tag> {
                new Tag {
                    Key = "Purpose",
                    Value = "test"
                }
            }
        }
    }
});


            

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

See Also