10

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?

Purusottam
  • 611
  • 6
  • 19

3 Answers3

16

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.

enter image description here

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.

I Bajwa PHD
  • 1,708
  • 1
  • 20
  • 42
3

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.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • 1
    Thanks for your response. Is there a link to get to this settings page or a screenshot to show where the link is? I don't see it anywhere in the Cost Explorer Page or Billing Preferences page. – Purusottam Jun 20 '20 at 14:08
  • 2
    For anyone who is looking for a link, here's how to get to the settings page: https://console.aws.amazon.com/cost-management/home#/settings – Purusottam Jun 20 '20 at 14:18
1

You can enable hourly reporting here

https://console.aws.amazon.com/cost-management/home?#/settings

enter image description here

The feature was released Nov 13, 2019 and you can find the costs associated here

https://aws.amazon.com/about-aws/whats-new/2019/11/aws-cost-explorer-supports-hourly-resource-level-granularity/

Judy007
  • 5,484
  • 4
  • 46
  • 68