User guide

string amiID = "ami-e189c8d1";
string keyPairName = "my-sample-key";
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = "t1.micro",
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
NetworkInterfaces = enis
};
ImageId
The ID of the AMI. For a list of public AMIs provided by Amazon, see Amazon Machine Images.
InstanceType
An instance type that is compatible with the specified AMI. For more information, see Instance
Types in the Amazon EC2 User Guide for Microsoft Windows Instances.
MinCount
The minimum number of EC2 instances to launch. If this is more instances than Amazon EC2
can launch in the target Availability Zone, Amazon EC2 launches no instances.
MaxCount
The maximum number of EC2 instances to launch. If this is more instances than Amazon EC2
can launch in the target Availability Zone, Amazon EC2 launches the largest possible number
of instances above MinCount.You can launch between 1 and the maximum number of instances
you're allowed for the instance type. For more information, see How many instances can I run
in Amazon EC2 in the Amazon EC2 General FAQ.
KeyName
The name of the EC2 key pair. If you launch an instance without specifying a key pair, you can't
connect to it. For more information, see Create a Key Pair (p. 73).
NetworkInterfaces
One or more network interfaces.
3. (Optional) To launch the instance with an IAM role (p. 108), specify an IAM instance profile in the
RunInstancesRequest.
Note that an IAM user can't launch an instance with an IAM role without the permissions granted by
the following policy.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": [
"iam:PassRole",
"iam:ListInstanceProfiles",
"ec2:*"
],
"Resource": "*"
}]
}
For example, the following snippet instantiates and configures an IamInstanceProfileSpecification
object for an IAM role named winapp-instance-role-1.
Version v2.0.0
77
AWS SDK for .NET Developer Guide
Tutorial: Creating Amazon EC2 Instances