0
我試圖構建一個報告,其中列出了一個特定賬戶已預先一次預先保留的所有實例費用。如何從使用API的AWS賬戶獲得列表保留實例(預先保留)使用API
我試圖構建一個報告,其中列出了一個特定賬戶已預先一次預先保留的所有實例費用。如何從使用API的AWS賬戶獲得列表保留實例(預先保留)使用API
此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);
}