Boto3 giving empty responses for 'Hourly' Cost Explorer queries

0

Hi,

I'm trying to use the recently added Hourly billing queries but I can't get it to work with boto3. I have had success using the very latest awscli (1.16.292), but version 1.10.28 of boto3 at least does not appear to work for me.

The query I'm using:

import boto3
from datetime import datetime, timedelta


CURRENT_HOUR = datetime.today().replace(minute=0,second=0,microsecond=0)
PREVIOUS_HOUR = CURRENT_HOUR - timedelta(hours=1)

aws_client = boto3.client(
    'ce',
    aws_access_key_id=AWS_ACCESS_KEY_ID,
    aws_secret_access_key=AWS_SECRET_ACCESS_KEY,
)

response = aws_client.get_cost_and_usage(
        TimePeriod={
            'Start': PREVIOUS_HOUR.isoformat() + 'Z',
            'End': CURRENT_HOUR.isoformat() + 'Z',
        },
        Granularity='HOURLY',
        Metrics=['UNBLENDED_COST'],
        GroupBy=[
            {
                'Type': 'DIMENSION',
                'Key': 'SERVICE'
            },
            {
                'Type': 'DIMENSION',
                'Key': 'LINKED_ACCOUNT'
            }
        ]
    )

Can anyone replicate this?

Edited by: ElliottIwoca on Nov 29, 2019 3:44 AM

Edited by: ElliottIwoca on Nov 29, 2019 3:48 AM

Edited by: ElliottIwoca on Nov 29, 2019 3:48 AM

asked 4 years ago529 views
1 Answer
0

OK, I worked out that the "HOURLY" responses will respond empty if they are too recent. The most recent response I got was around 31 hours ago, so I will query 2 days in the past to make sure I get a valid response.

answered 4 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions