I have created a basic script which will print the cost based on region, but the ask is can we able to get the cost splitup based on services in that particular region.
import boto3
import sys
# variable declaration
region_name = sys.argv[1]
start_period = sys.argv[2]
end_period = sys.argv[3]
Granularity = sys.argv[4]
aws_mgt_cons = boto3.session.Session(profile_name='profile-name',region_name=region_name)
aws_billing_cli = aws_mgt_cons.client('ce')
response = aws_billing_cli.get_cost_and_usage(
TimePeriod={
'Start': start_period,
'End': end_period
},
Granularity=Granularity,
Metrics=[
'AmortizedCost'
]
)
for responses in (response['ResultsByTime']):
start_date = responses['TimePeriod']['Start']
end_date = responses['TimePeriod']['End']
amount = responses['Total']['AmortizedCost']['Amount']
print(f"The Amount Spend Between {start_date} and {end_date} is ${amount}\n")