Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS billing with python

I'm want to extract my current billing from aws by using amazon boto3 library for python, but couldn't find any API command that does so.

When trying to use previous version (boto2) with the fps connection and get_account_balance() method, i'm waiting for a response with no reply.

Can anyone tell me the correct way of doing so ?

like image 559
Galpo Avatar asked Mar 08 '16 14:03

Galpo


People also ask

Can I use AWS with Python?

The AWS SDK for Python (Boto3) enables you to use Python code to interact with AWS services like Amazon S3. For example, you can use the SDK to create an Amazon S3 bucket, list your available buckets, and then delete the bucket you just created.

How is billing done in AWS?

Amazon Web Services automatically charges the credit card that you provided when you sign up for an AWS account. You can view or update your credit card information at any time, including designating a different credit card for AWS to charge. You can do this on the Payment Methods page in the Billing console.


1 Answers

You can get the current bill of your AWS account by using the CostExplorer API.

Below is an example:

import boto3

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

response = client.get_cost_and_usage(
    TimePeriod={
        'Start': '2018-10-01',
        'End': '2018-10-31'
    },
    Granularity='MONTHLY',
    Metrics=[
        'AmortizedCost',
    ]
)

print(response)
like image 157
captainblack Avatar answered Sep 29 '22 06:09

captainblack