Cost explorer boto3 "Charge type"

0

in Cost explorer UI there is a filter "Charge type" How could I apply the same filter using boto3?

As a reference I'm using documentation for boto3 CostExplorer.Client.get_cost_and_usage https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ce.html#CostExplorer.Client.get_cost_and_usage

I dont see anywhere in documentation filter description for "Charge type".

I tried to specify { "Not": { 'Dimensions': { 'Key': 'CHARGE_TYPE', 'Values': ['Refund'] } } }

but received an error:

botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetCostAndUsage operation: Dimension CHARGE_TYPE is not allowed. Allowed dimension(s): SAVINGS_PLAN_ARN, RESERVATION_ID, AZ, CACHE_ENGINE, INSTANCE_TYPE_FAMILY, INSTANCE_TYPE, SAVINGS_PLANS_TYPE, PURCHASE_TYPE, INVOICING_ENTITY, LINKED_ACCOUNT, REGION, SERVICE, LEGAL_ENTITY_NAME, USAGE_TYPE, PLATFORM, USAGE_TYPE_GROUP, OPERATION, OPERATING_SYSTEM, DATABASE_ENGINE, TENANCY, BILLING_ENTITY, RECORD_TYPE, DEPLOYMENT_OPTION

asked a year ago360 views
2 Answers
2

There is a description of each of the dimensions located here: https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_GetDimensionValues.html

You are looking for RECORD_TYPE.

answered a year ago
  • Hi Geno_E, thank you this is relly useful

  • So we can't use charge type in boto3 or through cost explorer api ?.

    If yes , can you provide any documentation?

0

Correct keyword to use Charge Type in boto3 is using RECORD_TYPE. For more info, click here

Example:-

Filter={
        "Not":
        {
            'Dimensions':{
            'Key': 'RECORD_TYPE',
            'Values':['Credit','Refund']
             }
        }
    },

Add the above code to your get_cost_and_usage() function and you can exclude credits.

answered 12 days 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