User guide

Table Of Contents
{
"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.
var instanceProfile = new IamInstanceProfile();
instanceProfile.Id = "winapp-instance-role-1";
instanceProfile.Arn = "arn:aws:iam::4444-5555-6666:instance-profile/winapp-
instance-role-1";
To specify this instance profile in the RunInstancesRequest object, add the following line.
InstanceProfile = instanceProfile
3. Launch the instances by passing the request object to the RunInstances method. Save the IDs of
the instances, as you need them to manage the instances.
Use the returned RunInstancesResponse object to get a list of instance IDs for the new instances.
The Reservation.Instances property contains a list of Instance objects, one for each EC2 instance
that you successfully launched.You can retrieve the ID for each instance from the Instance object's
InstanceId property.
var launchResponse = ec2Client.RunInstances(launchRequest);
List<Instance> instances = launchResponse.Reservation.Instances;
List<String> instanceIds = new List<string>();
foreach (Instance item in instances)
{
instanceIds.Add(item.InstanceId);
Console.WriteLine();
Console.WriteLine("New instance: " + item.InstanceId);
Console.WriteLine("Instance state: " + item.State.Name);
}
To launch an EC2 instance in a VPC
1. Create and initialize a network interface.
string subnetID = "subnet-cb663da2";
List<string> groups = new List<string>() { mySG.GroupId };
var eni = new InstanceNetworkInterfaceSpecification()
Version v2.0.0
43
AWS SDK for .NET Developer Guide
Launch an EC2 Instance