Here is the main code to get results. No matter whether I use offset
or not, tokens keep repeating.
offset = 0
limit = 50000
filters = ['enhanced_service_name==AWS EC2']
cost_data = []
response = cldy.cost_reports.list_cost_reports(
start_date=start_date,
end_date=end_date,
dimensions=dimensions,
metrics=metrics,
filters=filters,
offset=offset,
limit=limit,
view_id=view_id)
if not 'results' in response:
pprint(response)
sys.exit(1)
cost_data.extend(response['results'])
print(f'Current quantity: {len(cost_data)}')
token = response.get('pagination', {}).get('next', '')
print(f'{token=}')
while token != '' and len(cost_data) < 1000000:
response = cldy.cost_reports.list_cost_reports(
start_date=start_date,
end_date=end_date,
dimensions=dimensions,
metrics=metrics,
filters=filters,
offset=offset,
limit=limit,
view_id=view_id,
token=token)
offset += limit
cost_data.extend(response['results'])
print(f'Current quantity: {len(cost_data)}')
token = response.get('pagination', {}).get('next', '')
print(f'{token=}')
print(f'{len(cost_data)} entries loaded')
Class Cldy contains functions that use requests library to access each endpoint. For list_cost_reports
function the endpoint is https://api.cloudability.com/v3/reporting/cost/run
.
#Cloudability