I am building a python dashboard so that my clients who I have applications hosted on AWS can pay the exact amount there project costs me. I am using the python sdk but I only get my accounts overall amounts from my queries.
I have been sure to add the tags to the projects (ex: elastic beanstalk) and activated the cost allocation tags but it has been to no avail.
cost_allocation_tag = 'Company'
client = boto3.client(
'ce',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
)
try:
monthly = client.get_cost_and_usage(
TimePeriod={
'Start':end,
'End':now.strftime('%Y-%m-%d')
},
Granularity='MONTHLY',
Metrics=[
'BlendedCost',
],
GroupBy=[
{
'Type': 'TAG',
'Key': cost_allocation_tag
},
]
)
monthly_cost = monthly['ResultsByTime'][0]['Groups'][0]['Metrics']['BlendedCost']['Amount']
except:
pass
I should get costs only associated with the tags not the overall. I have read the documentation but I am not 100% on if I followed it correctly. Here is the link to the docs