Is there any way to query more than 14 days including the resource_id dimension?
import json
from datetime import datetime, timedelta, timezone
import boto3
UTC_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
DAYS=14
GRANULARITY="MONTHLY"
def get_start_end_date():
end_date = datetime.now(timezone.utc)
start_date = end_date - timedelta(days=DAYS)
return start_date.date(), end_date.date()
start, end = get_start_end_date()
response = ce_client.get_cost_and_usage_with_resources(
TimePeriod={
"Start": start.strftime(UTC_TIMESTAMP_FORMAT),
"End": end.strftime(UTC_TIMESTAMP_FORMAT),
},
Granularity=GRANULARITY,
Filter={
"Not": {
"Dimensions": {
"Key": "RESOURCE_ID",
"Values": [
"Credit"
],
}
}
},
Metrics=["UsageQuantity", "BlendedCost"],
GroupBy=[
{
"Type": "DIMENSION",
"Key": "RESOURCE_ID",
},
],
)
No matter what GRANULARITY is set to, setting DAYS > 14 leads to
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetCostAndUsageWithResources operation: start date is too old for hourly, the max supported days for hourly granularity is 14 days
Did anyone manage to query resource level data somehow for more than 14 days?
I found a ticket from 2020 with the same issue: https://github.com/boto/boto3/issues/2369
Hi, Shlomo is 100% right. Pls, if you need to confirm, look at https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ce/client/get_cost_and_usage_with_resources.html
Section PARAMETERS > TimePeriod is explicit on this matter
The CUR only starts working from when it is created. I am looking for data that is ~1 year old without having created a CUR back then.