如何在 AWS 中启用成本和使用数据的小时粒度?
How to enable hourly granularity for cost and usage data in AWS?
我正在尝试调用 AWS 的 get-cost-and-usage api 来生成每小时报告。但是,我在启用仅选择加入功能时遇到错误。
aws ce get-cost-and-usage --time-period '{"Start": "2020-06-10T00:00:00Z", "End": "2020-06-15T00:00:00Z"}' --granularity 'HOURLY' --metrics "AmortizedCost" "BlendedCost" "NetAmortizedCost" "NetUnblendedCost" "NormalizedUsageAmount" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE
错误信息:
An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation: Hourly data granularity is an opt-in only feature. You can be enable this feature from the PAYER account’s Cost Explorer Settings page.
我没有看到任何启用此功能的设置页面。有没有办法通过控制台或 cli 启用此功能?
您可以在 AWS Cost Explorer 设置页面上选择以小时为粒度。
如果您只有一个帐户,这可以在帐户内完成。
如果您的账户是 AWS 组织的一部分,则必须从该组织的付款人账户完成。
很多文档链接中都有提到。
Hourly data granularity is an opt-in only feature.
而当我们执行 CE API 时,它也会抛出错误。
An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation: Hourly data granularity is an opt-in only feature. You can be enable this feature from the PAYER account’s Cost Explorer Settings page.
但是没有任何地方提供截图或详细信息。
我附上屏幕截图,如何启用“每小时和资源级别数据”,例如选择加入每小时数据粒度。
我使用的是整合账单账户,因此主要付款人账户需要此设置。
关于此设置还有几点需要考虑:
Allow all accounts to access hourly and resource-level information for
the past 14 days. Resource-level information is only available for
your Amazon EC2 service usage.
Please note that it can take up to 24 hours for your data to become
available, and a cost of [=13=].01 per 1,000 UsageRecords-month will be
incurred as a result of storing and accessing your hourly- and
resource-level information. A UsageRecord is defined as one line of
usage. For example, one EC2 instance running for 24 hours will
generate 24 distinct UsageRecords at the hourly granularity.
这样设置后,就可以运行CEAPI调用了。例如
aws ce get-cost-and-usage --time-period Start="2020-07-07T10:00:00Z",End="2020-07-07T11:00:00Z" --granularity HOURLY --metrics "BlendedCost" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment
需要注意的一点是,如果是 HOURLY,时间格式必须是 yyyy-MM-ddThh:mm:ssZ 格式。
您可以在此处启用每小时报告
https://console.aws.amazon.com/cost-management/home?#/settings
该功能于 2019 年 11 月 13 日发布,您可以在此处找到相关费用
我正在尝试调用 AWS 的 get-cost-and-usage api 来生成每小时报告。但是,我在启用仅选择加入功能时遇到错误。
aws ce get-cost-and-usage --time-period '{"Start": "2020-06-10T00:00:00Z", "End": "2020-06-15T00:00:00Z"}' --granularity 'HOURLY' --metrics "AmortizedCost" "BlendedCost" "NetAmortizedCost" "NetUnblendedCost" "NormalizedUsageAmount" "UnblendedCost" "UsageQuantity" --group-by Type=DIMENSION,Key=SERVICE
错误信息:
An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation: Hourly data granularity is an opt-in only feature. You can be enable this feature from the PAYER account’s Cost Explorer Settings page.
我没有看到任何启用此功能的设置页面。有没有办法通过控制台或 cli 启用此功能?
您可以在 AWS Cost Explorer 设置页面上选择以小时为粒度。
如果您只有一个帐户,这可以在帐户内完成。
如果您的账户是 AWS 组织的一部分,则必须从该组织的付款人账户完成。
很多文档链接中都有提到。
Hourly data granularity is an opt-in only feature.
而当我们执行 CE API 时,它也会抛出错误。
An error occurred (AccessDeniedException) when calling the GetCostAndUsage operation: Hourly data granularity is an opt-in only feature. You can be enable this feature from the PAYER account’s Cost Explorer Settings page.
但是没有任何地方提供截图或详细信息。 我附上屏幕截图,如何启用“每小时和资源级别数据”,例如选择加入每小时数据粒度。
我使用的是整合账单账户,因此主要付款人账户需要此设置。
关于此设置还有几点需要考虑:
Allow all accounts to access hourly and resource-level information for the past 14 days. Resource-level information is only available for your Amazon EC2 service usage.
Please note that it can take up to 24 hours for your data to become available, and a cost of [=13=].01 per 1,000 UsageRecords-month will be incurred as a result of storing and accessing your hourly- and resource-level information. A UsageRecord is defined as one line of usage. For example, one EC2 instance running for 24 hours will generate 24 distinct UsageRecords at the hourly granularity.
这样设置后,就可以运行CEAPI调用了。例如
aws ce get-cost-and-usage --time-period Start="2020-07-07T10:00:00Z",End="2020-07-07T11:00:00Z" --granularity HOURLY --metrics "BlendedCost" --group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=Environment
需要注意的一点是,如果是 HOURLY,时间格式必须是 yyyy-MM-ddThh:mm:ssZ 格式。
您可以在此处启用每小时报告
https://console.aws.amazon.com/cost-management/home?#/settings
该功能于 2019 年 11 月 13 日发布,您可以在此处找到相关费用