- Newest
- Most votes
- Most comments
Hello mburger,
You're finding different values because CE API deals with End (in TimePeriod) as exclusive. The boto3 documentation says:
The end of the time period that you want the usage and costs for. The end date is exclusive. For example, if end is 2017-05-01 , AWS retrieves cost and usage data from the start date up to, but not including, 2017-05-01.
With that in place, promote the following changes in your code to find the same you saw at the screenshot:
client = boto3.client("ce")
total_cost = client.get_cost_and_usage(
TimePeriod={"Start": '2023-03-01', "End": '2023-04-01'},
Granularity="MONTHLY",
Metrics=["AmortizedCost"],
)["ResultsByTime"]
print(total_cost)
After test it, share your findings!
Hi I'm having the same issue.
Even when I try to fetch the details as below does not include "TimePeriod": {"Start": "2024-11-17", "End": "2024-11-18"} in the response.
As per the documentation it says whereas when timeperiod is from 11th - 18th it does not include 17th date
TimePeriod (dict) -- Sets the start and end dates for retrieving AWS costs. The start date is inclusive, but the end date is exclusive. For example, if start is 2017-01-01 and end is 2017-05-01 , then the cost and usage data is retrieved from 2017-01-01 up to and including 2017-04-30 but not including 2017-05-01 .
client = boto3.client("ce")
total_cost = client.get_cost_and_usage(
TimePeriod={"Start": '2024-11-11', "End": '2024-11-18'},
Granularity="DAILY",
Metrics=["UnblendedCost"],
GroupBy=[
{'Type': 'DIMENSION', 'Key': 'USAGE_TYPE'}
]
)["ResultsByTime"]
date = []
for result in total_cost:
date.append(result['TimePeriod'])
print(date)
#[{'Start': '2024-11-11', 'End': '2024-11-12'}, {'Start': '2024-11-12', 'End': '2024-11-13'}, {'Start': '2024-11-13', 'End': '2024-11-14'}, {'Start': '2024-11-14', 'End': '2024-11-15'}, {'Start': '2024-11-15', 'End': '2024-11-16'}, {'Start': '2024-11-16', 'End': '2024-11-17'}]
Hello, check if Cost Explorer you're seeing it Aggregating costs by 'Amortized' (in Advanced options section). It seems that the screenshot was get with Unblended (the default).
Yes - Cost Explorer shows the same number regardless of whether using "Amortized" or "Unblended" data sets. The screenshot was taken using "Amortized".
Worth noting that the API also reports the same cost regardless of which basis is used (Amortized or Unblended)
I've updated the screenshot to show the advanced settings as well.
Relevant content
- asked 10 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago

Yes, that brings the numbers into alignment, thank you for your help!