AWS costs, usage, and credits

0

I have been using boto3.get_cost_and_usage to get the daily aws account service fees, but recently I used points to deduct the fees in April. The points are still left, but when I started to get the service fees through boto3.get_cost_and_usage in May, the prompt was always 0. .I checked get_cost_and_usage and did not find a good solution quickly. In the aws console, I can check the daily expenses by setting not to include refund and credit.

Dennis
asked a month ago92 views
1 Answer
2
Accepted Answer

Hello.

I think you can use the "Filter" in the parameters to get the price without including credits.
The code below is a sample, but when I run it in my environment, I was able to check the charges that do not include credits.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ce/client/get_cost_and_usage.html#

import boto3

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

client = boto3.client('ce', region_name='us-east-1')

response = client.get_cost_and_usage(
        TimePeriod={
            'Start': '2024-05-05',
            'End': '2024-05-06'
        },
        Filter=MY_FILTER,
        Granularity='DAILY',
        Metrics=['AmortizedCost']
        )

print(response)
profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month 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