首页 > 解决方案 > 以编程方式获取 AWS 成本和使用情况报告的内容

问题描述

我们每月都会安排进入S3 存储桶的报告。这些报告包括成本和使用信息(通过Cost Explorer配置)。

我不想从 S3 手动下载文件,而是希望能够随时以编程方式下载相同的内容(模式)。我在 S3 文件中有以下列(只是一个摘要,因为列表很长):

identity-oriented
bill-oriented
lineItem-oriented
product-oriented
pricing-oriented
reservation-oriented
savingsPlan-oriented
resourceTags-oriented

所以,与其等到月底才能获得这些内容,我希望能够每天查询它。可能某些列的值不会被精确计算(我知道一些调整通常发生在计费期间)。我找到的最接近的 CLI/API 如下:https ://awscli.amazonaws.com/v2/documentation/api/latest/reference/ce/get-cost-and-usage.html#get-cost-and-用法,但我觉得它不是那么强大(或者至少我不知道如何进行查询)以返回接近上述模式的模式。

我尝试过的是以下内容:

aws ce get-cost-and-usage --time-period Start=2021-05-25,End=2021-05-26 --granularity DAILY --metrics "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Project

它返回一些内容,但还远远不够。我还想包括SUBSCRIPTION_ID、定价货币、定价单位、使用量等。我希望有一个端点来返回预定报告中的内容。

如果我尝试以某种方式访问​​另一个维度(或另一个标签),我会继续得到:

An error occurred (ValidationException) when calling the GetCostAndUsage operation: Only two values for GroupBy are allowed

标签: amazon-web-servicesamazon-s3

解决方案


推荐阅读