How can I get a list reserved instances (reserved in advance) from a AWS account using API
I am trying to build a report where I list all the instances that 开发者_如何学编程a particular account has that have been reserved in advance with one time upfront fee.
This C# code will give you the list of reserved instances that you have:
AmazonEC2 ec2 = AWSClientFactory.CreateAmazonEC2Client(
accessKey,
secretAccessKey
);
DescribeReservedInstancesRequest request = new DescribeReservedInstancesRequest();
try
{
DescribeReservedInstancesResponse response = ec2.DescribeReservedInstances(request);
foreach (ReservedInstances ri in response.DescribeReservedInstancesResult.ReservedInstances)
{
Console.WriteLine(ri.ReservedInstancesId + "\t" + ri.InstanceType + "\t" + ri.InstanceCount.ToString() + "\t" + ri.PurchaseState);
}
}
catch (AmazonEC2Exception ex)
{
Console.WriteLine("Caught Exception: " + ex.Message);
Console.WriteLine("Response Status Code: " + ex.StatusCode);
Console.WriteLine("Error Code: " + ex.ErrorCode);
Console.WriteLine("Error Type: " + ex.ErrorType);
Console.WriteLine("Request ID: " + ex.RequestId);
Console.WriteLine("XML: " + ex.XML);
}
精彩评论