User guide
Table Of Contents
- AWS SDK for .NET
- Table of Contents
- AWS SDK for .NET Developer Guide
- Getting Started with the AWS SDK for .NET
- Programming with the AWS SDK for .NET
- AWS SDK for .NET Tutorials and Examples
- Managing ASP.NET Session State with Amazon DynamoDB
- Tutorial: Creating Amazon EC2 Instances with the AWS SDK for .NET
- Tutorial: Grant Access Using an IAM Role and the AWS SDK for .NET
- Tutorial: Amazon EC2 Spot Instances
- Creating and Using an Amazon SQS Queue with the AWS SDK for .NET
- Creating an Amazon Route 53 Hosted Zone and Adding Resource Record Sets
- Additional Resources
- Document History

Checking the State of Your Instance
Use the following procedure to get the current state of your instance. Initially, your instance is in the
pending state.You can connect to your instance after it enters the running state.
To check the state of your instance
1. Create and configure a DescribeInstancesRequest object. Assign a list of instance IDs to the InstanceId
property and use the Filter property to limit the request to certain instances, such as instances with
a particular user-specified tag.
var instancesRequest = new DescribeInstancesRequest();
instancesRequest.InstanceId = instanceIDs;
2. Call the EC2 client's DescribeInstances method, and pass it the request object from step 1. The
method returns a DescribeInstancesResponse object with the descriptions.
var statusResponse = ec2Client.DescribeInstances(instancesRequest);
3. Enumerate the running instances and determine their status.The DescribeInstancesResult.Reserva-
tions property contains a list of reservations. In this case, there is only one. Each reservation contains
a list of Instance objects.You can get the instance's status from the InstanceState.Name property.
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 Elastic Compute Cloud User Guide for Microsoft
Windows.
When you have finished with your EC2 instance, see Terminate an EC2 Instance (p. 46).
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 in-
stances.
Pass the request object to the client object's TerminateInstances method.
Version v2.0.0
46
AWS SDK for .NET Developer Guide
Terminate an EC2 Instance