User guide

RunInstancesResponse runResponse = ec2Client.RunInstances(runInstances
Request);
3. You can use the returned RunInstancesResponse object to get a list of instance IDs for the new
instances.
List<Instance> instances = runResponse.Reservation.Instances;
List<String> instanceIDs = new List<string>();
foreach (Instance item in instances)
{
instanceIDs.Add(item.InstanceId);
}
You need the instance IDs, in particular, to check status and terminate instances. This enumeration
also allows you to determine how many instances were actually launched. The response object's
runResponse.RunInstancesResult.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.
After you create your Amazon EC2 instances, you can check their status programmatically.
To check EC2 status
1. Create and configure a DescribeInstancesRequest object.
var instancesRequest = new DescribeInstancesRequest();
instancesRequest.InstanceId = instanceIDs;
To configure the object, assign a list of instance IDs to the InstanceId property.You can use the
object's Filter property to limit the request to certain instances, such as instances with a particular
user-specified tag.
2. Call the EC2 client's DescribeInstances method, and pass it the request object from Step 1.
DescribeInstancesResponse statusResponse = ec2Client.DescribeInstances(in
stancesRequest);
The method returns a DescribeInstancesResponse object with the descriptions.
3. Enumerate the running instances and determine their status.
List<Instance> runningInstances = statusResponse.DescribeInstancesResult.Re
servation[0].Instance;
foreach (Instance instance in runningInstances)
{
Console.WriteLine("Instance Status: " + instance.InstanceState.Name);
}
Version v2.0.0
50
AWS SDK for .NET Developer Guide
Launch Amazon EC2 Instances