AWS cost explorer dashboard and CLI result mismatch

0

Hello, So i'm having trouble making the 'aws ce get-cost-and-usage' command work and get me the same result I get using the cost explorer console cost explorer dashboard applied filters are:

  • Date range: 2023-04-01 2023-04-10
  • Granularity: Monthly
  • Dimension: Linked Account
  • Charge type: excludes 2 (refund, credit)
  • Aggregate Costs by: Blended cost

Now here's the command I run: $ aws ce get-cost-and-usage --time-period Start=2023-04-01,End=2023-04-11 --granularity MONTHLY --group-by Type=DIMENSION,Key=LINKED_ACCOUNT --metrics "BlendedCost"

and here's the output I get:

{
    "GroupDefinitions": [
        {
            "Type": "DIMENSION",
            "Key": "LINKED_ACCOUNT"
        }
    ],
    "ResultsByTime": [
        {
            "TimePeriod": {
                "Start": "2023-04-01",
                "End": "2023-04-11"
            },
            "Total": {},
            "Groups": [
                {
                    "Keys": [
                        "aaaa"
                    ],
                    "Metrics": {
                        "BlendedCost": {
                            "Amount": "6.136607832",
                            "Unit": "USD"
                        }
                    }
                },
                {
                    "Keys": [
                        "bbbb"
                    ],
                    "Metrics": {
                        "BlendedCost": {
                            "Amount": "0.3097750801",
                            "Unit": "USD"
                        }
                    }
                },
                {
                    "Keys": [
                        "cccc"
                    ],
                    "Metrics": {
                        "BlendedCost": {
                            "Amount": "-0.0046580685",
                            "Unit": "USD"
                        }
                    }
                }
            ],
            "Estimated": true
        }
    ],
    "DimensionValueAttributes": [
        {
            "Value": "aaaa",
            "Attributes": {
                "description": "L****"
            }
        },
        {
            "Value": "bbbb",
            "Attributes": {
                "description": "Preprod"
            }
        },
        {
            "Value": "cccc",
            "Attributes": {
                "description": "Prod"
            }
        }
    ]
}

What are these weird negatives and very low values I get for each account compared to the result I get on the dashboard? what is missing on my command so I could get the same result on the dashboard ?

Thank you

2 Answers
0
Accepted Answer

It looks like the reason you are seeing different results in Cost Explorer console vs. CLI command is that you have different filters applied. In Console, you are filtering on Charge Type to exclude refunds and credits. Without these exclusions in the CLI command, its possible you are getting total costs that include refunds and credits.
Try: aws ce get-cost-and-usage --time-period Start=2023-04-01,End=2023-04-11 --granularity MONTHLY --metrics BLENDED_COST --group-by Type=DIMENSION,Key=LINKED_ACCOUNT --filter Dimensions={Key=RECORD_TYPE,Values=Usage}

If you need to find all the specific record type (charge type) values, you can also use: aws ce get-dimension-values --dimension RECORD_TYPE --time-period Start=2023-04-01,End=2023-04-11

AWS
answered a year ago
  • thank you, even though the command you mentioned doesn't work, syntax problem , but I could make it work using an external file:

    { "Dimensions": { "Key": "RECORD_TYPE", "Values": ["Usage","Tax","Support"] } }

    -then call it with $ aws ce get-cost-and-usage --time-period Start=2023-04-09,End=2023-04-17 --granularity MONTHLY --metrics BLENDED_COST --group-by Type=DIMENSION,Key=LINKED_ACCOUNT --filter file://file.json

0

@vjtean saying "In the command it says End=2023-04-11 instead of End=2023-04-10" Reply: According to AWS documentation, end_date is exclusive, so in order to include 10th April into account, you must mention the day after. even if that was the problem (which is not), it clearly doesn't explain negative and lower than 0 values.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions