User guide
The DescribeInstancesResponse object's DescribeInstancesResult.Reservations property
contains a list of reservations. In this case, there is only one. Each reservation contains a list of
Instance objects, each of which represents one of the reservation's EC2 instances.You can get the
instance's status from an Instance object's InstanceState.Name property, which can have one of
the following values: "pending", "running", "shutting-down", "terminated", "stopping", "stopped".
After an instance is running, you can remotely connect to it by using an SSH/RDP client on your computer.
Before connecting to your Amazon EC2 instance, you must ensure that the instance’s SSH/RDP port is
open to traffic.To connect, you will need the Amazon EC2 instance ID and the private key from instance's
key pair. For information about how to obtain the private key, see Create a Key Pair (p. 47). For more
information about how to connect to an EC2 instance, see Connecting to Instances.
Next: Terminate Amazon EC2 Instances (p. 51)
Terminate Amazon EC2 Instances
When you no longer need one or more of your Amazon EC2 instances, you can terminate them, as
follows:
To terminate EC2 instances
1. Create and initialize a TerminateInstancesRequest object.
var termRequest = new TerminateInstancesRequest();
termRequest.InstanceId = instanceIDs;
Set the object's InstanceIds property to a list of the instance IDs that you want to terminate.
2. Pass the request object to the Amazon EC2 client object's TerminateInstances method.
TerminateInstancesResponse termResponse = ec2Client.TerminateInstances(ter
mRequest);
You can use the response object to list the terminated instances, as follows:
List<InstanceStateChange> terminatedInstances = termResponse.TerminateInstances
Result.TerminatingInstance;
foreach(InstanceStateChange item in terminatedInstances)
{
Console.WriteLine("Terminated Instance: " + item.InstanceId);
}
Next: Additional Amazon EC2 Resources (p. 51)
Additional Amazon EC2 Resources
The following table lists related resources that you'll find useful when using Amazon EC2 with the AWS
SDK for .NET.
Version v2.0.0
51
AWS SDK for .NET Developer Guide
Terminate Amazon EC2 Instances