开发者

How can I get a list reserved instances (reserved in advance) from a AWS account using API

开发者 https://www.devze.com 2023-01-27 23:36 出处:网络
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

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消