Reputation: 1
I am trying to get the cost of the previous day using cost explorer while using boto
and lambda
. But I get and error
" "errorMessage": "An error occurred (ValidationException) when calling the GetCostAndUsage operation: " and the error type is "ClientError".
I have specified the region to us-east-1
. Also my policy is
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ce:*"
],
"Resource": [
"*"
]
}
]
}
My Code is below
ce = boto3.client('ce')
cost = ce.get_cost_and_usage(TimePeriod={'Start': '2019-7-15', 'End': '2019-7-17'}, Granularity = 'DAILY')
print(cost)
Upvotes: 0
Views: 3514
Reputation: 2710
I think you have two problems:
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetCostAndUsage operation: Start time is invalid. Valid format is: yyyy-MM-dd.
Metrics
keyword to the get_cost_and_usage()
call.Changing your get_cost_and_usage()
call to something like this should work:
cost = ce.get_cost_and_usage(
TimePeriod={'Start': '2019-07-15', 'End': '2019-07-17'},
Granularity = 'DAILY',
Metrics=['UnblendedCost'])
Upvotes: 1