How can I get all data transfer costs from my aws account? is there any boto3 api that would support it? PS- I require all kinds of data transfer costs, for all regions.
Asked
Active
Viewed 363 times
-1
-
No there is no API for that. YOu have to request and parse cost and usage reports. – Marcin Dec 27 '21 at 09:43
1 Answers
1
You can use the Boto3 - Cost Explorer library.
Specify the time period and filters you want to apply. In your case, to get Data Transfer cost across all regions the code should be similar to this (change parameters accordingly):
import boto3
client = boto3.client('ce')
def lambda_handler(event, context):
response = client.get_cost_and_usage(
TimePeriod={
'Start': '2021-06-01',
'End': '2021-12-01'
},
Filter={
'Dimensions': {
'Key': 'USAGE_TYPE_GROUP',
'Values': [
'EC2: Data Transfer - Internet (Out)'
],
'MatchOptions': [
'EQUALS',
]
}
},
Granularity='MONTHLY',
Metrics=['UnblendedCost']
)
print(response)

OARP
- 3,429
- 1
- 11
- 20