User guide

List<Instance> runningInstances = statusResponse.DescribeInstancesResult.Re
servation[0].Instance;
foreach (Instance instance in runningInstances)
{
Console.WriteLine("Instance status: " + instance.InstanceState.Name);
}
Connecting to Your Running Instance
After an instance is running, you can remotely connect to it using an RDP client on your computer. Before
connecting to your instance, you must ensure that the instance's RDP port is open to traffic.To connect,
you need the instance ID and the private key for instance's key pair. For more information, see Connecting
to Your Windows Instance Using RDP in the Amazon EC2 User Guide for Microsoft Windows Instances.
When you have finished with your EC2 instance, see Terminate an EC2 Instance (p. 79).
Terminate an EC2 Instance Using the SDK for .NET
When you no longer need one or more of your EC2 instances, you can terminate them.
To terminate an EC2 instance
Create and initialize a TerminateInstancesRequest object. Set the InstanceIds property to a list of one or
more instance IDs. In this example, instanceIds is the list that you saved when you launched the
instances.
Pass the request object to the client object's TerminateInstances method.
var deleteRequest = new TerminateInstancesRequest()
{
InstanceIds = instanceIds
};
var deleteResponse = ec2Client.TerminateInstances(deleteRequest);
foreach (InstanceStateChange item in deleteResponse.TerminatingInstances)
{
Console.WriteLine();
Console.WriteLine("Terminated instance: " + item.InstanceId);
Console.WriteLine("Instance state: " + item.CurrentState.Name);
}
To list the terminated instances
You can use the response object as follows to list the terminated instances.
List<InstanceStateChange> terminatedInstances = termResponse.TerminateInstances
Result.TerminatingInstance;
foreach(InstanceStateChange item in terminatedInstances)
{
Console.WriteLine("Terminated Instance: " + item.InstanceId);
}
Version v2.0.0
79
AWS SDK for .NET Developer Guide
Tutorial: Creating Amazon EC2 Instances