我正在尝试构建一个报告,其中列出了预先保留一次预付费的特定帐户的所有实例。
答案 0 :(得分:0)
此C#代码将为您提供您拥有的保留实例列表:
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);
}