I am trying to call get-cost-and-usage api of AWS to generate hourly report. But, i am getting an error around enabling an opt-in only feature.
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
Error Message:
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.
I don't see any settings page to enable this feature. Is there any way to enable this feature, via console or cli?
You can opt-in to hourly granularity on the AWS Cost Explorer Settings page. If you have a single account, this can be done inside the account. If your account is part of an AWS Organization, it must be done from the Organization's payer account.
AWS Cost Explorer has an easy-to-use interface that lets you visualize, understand, and manage your AWS costs and usage over time. Get started quickly by creating custom reports that analyze cost and usage data.
AWS Budgets displays current, budgeted, and forecasted cost and usage data. Cost Explorer does not just display historical data. It also provides recommendations for optimizing your cloud spend.
AWS Cost and Usage Reports tracks your AWS usage and provides estimated charges associated with your account. Each report contains line items for each unique combination of AWS products, usage type, and operation that you use in your AWS account.
It is mentioned in many documentation links about.
Hourly data granularity is an opt-in only feature.
And when we execute the CE API, it also throws the error.
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.
But no screenshot or detailed information is provided any where. I am attaching the screenshot, How to enable "Hourly and Resource Level Data" e.g opt-in for Hourly data granularity.
I am using consolidated Billing account, so this setting is needed in main Payer's account.
Few things more to consider about this settings:
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 $0.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.
After this settings, you can run CE API Calls. e.g
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
One thing to note is that, in case of HOURLY, the time format must be in yyyy-MM-ddThh:mm:ssZ format.
You can opt-in to hourly granularity on the AWS Cost Explorer Settings page.
If you have a single account, this can be done inside the account.
If your account is part of an AWS Organization, it must be done from the Organization’s payer account.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With