我想使用 Cost Explorer API 获取我的 EC2 实例的使用情况和成本。
我能够成功获得使用量和成本,但成本和使用量包括 EC2 实例和 EBS 卷完成的使用量,所以我想使用usage_type_group
诸如EC2 :Running Hours
但每当我通过时我没有得到任何价值. 如果我删除它,我会得到总使用量和成本的价值。
DimensionValues dimensions = new DimensionValues();
dimensions.setKey("USAGE_TYPE_GROUP");
Collection<String> values = new ArrayList<>();
values.add("EC2 : Running Hours");
dimensions.setValues(values);
filter.setDimensions(dimensions);
GetCostAndUsageRequest getCostAndUsageRequest = new GetCostAndUsageRequest().withGroupBy(groupBy)
.withTimePeriod(dateInterval).withGranularity(Granularity.MONTHLY)
.withFilter(filter)
.withMetrics("UsageQuantity")
.withMetrics("BlendedCost");
try {
costInformation = costExplorer.getCostAndUsage(getCostAndUsageRequest);
} catch (AWSCostExplorerException ex) {
logger.error("cost fetch details failed from cost explorer " + ex.getErrorMessage());
}