Different Total Cost in Cost Explorer vs API

4

Hi,

I'm having an issue related to a discrepancy between what is shown in the Cost Explorer and Billing pages in the AWS console vs what is returned over the API.

Previous to March 2023, both views (console and API) would show the same total cost. March 2023 was the first month we implemented a Savings Plan so we changed from using the Unblended data set to using Amortized (this change was applied to both our console settings and API usage) - I believe the Savings Plan is the source of this issue somehow, since it just showed up this month.

Viewing our cost for March 2023 in Cost Explorer shows the total cost as $17,409 as seen here:

Cost in console

However, when attempting to pull the same data over the API, it shows $16,843 as the total cost for the month. The code used to query the API is the following in Python:

    client = boto3.client("ce")
    total_cost = client.get_cost_and_usage(
        TimePeriod={"Start": '2023-03-01', "End": '2023-03-31'},
        Granularity="MONTHLY",
        Metrics=["AmortizedCost"],
    )["ResultsByTime"]
    print(total_cost)
# -> [{'TimePeriod': {'Start': '2023-03-01', 'End': '2023-03-31'}, 'Total': {'AmortizedCost': {'Amount': '16843.7283177265', 'Unit': 'USD'}}, 'Groups': [], 'Estimated': False}]

This discrepancy exists no matter which data set I use (unblended or amortized) and also only exists for March 2023.

Does anyone have insight on how I might rectify? We rely on the API for running some cost analysis that can't be done through the console but if it's giving inaccurate costs we can't use it.

Thanks!

mburger
질문됨 일 년 전1168회 조회
2개 답변
2
수락된 답변

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!

AWS
답변함 일 년 전
profile picture
전문가
검토됨 9달 전
profile pictureAWS
전문가
검토됨 10달 전
  • Yes, that brings the numbers into alignment, thank you for your help!

-1

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).

AWS
답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠