- 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!
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
- Accepted Answerasked 2 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
Yes, that brings the numbers into alignment, thank you for your help!