0

I am using get_cost_and_usage from cost explorer API. I want to get billing details for individual things. I followed their documentation and created a new billing group named (user:company) Inside managed option of IOT Core. Added 4 new devices inside this newly created biling group with tagName user:company and value IPMS . Then in Cost Allocation Tags console, I Activated this tag (user:company).

But I am unable to get billing related to these things. Here is my python code

response = client.get_cost_and_usage(
    TimePeriod={
       'Start': '2019-07-01',
       'End': '2019-07-16'
    },
    Granularity='MONTHLY',
    Filter={
        'Tags':{
            'Key': 'user:company',
            'Values': [
               'IPMS'
            ]
        }
    },
    Metrics=[
        'UnblendedCost',
    ],
    GroupBy=[
         {
            'Type': 'TAG',
            'Key': 'user:company'
         },
    ]),

and here is response

{"ResponseMetadata": {"RetryAttempts": 0, "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "034a2efb-1ba2-4272-b595-d07d0e5c9931", "content-type": "application/x-amz-json-1.1", "content-length": "216", "date": "Thu, 18 Jul 2019 16:49:33 GMT"}, "RequestId": "034a2efb-1ba2-4272-b595-d07d0e5c9931"}, "GroupDefinitions": [{"Key": "user:company", "Type": "TAG"}], "ResultsByTime": [{"TimePeriod": {"End": "2019-07-16", "Start": "2019-07-01"}, "Total": {"UnblendedCost": {"Amount": "0", "Unit": "USD"}}, "Estimated": true, "Groups": []}]}

event I am not able to get my defined tag in get_tags API

here is sample code

response = client.get_tags(

TimePeriod={
    'Start': '2019-07-01',
    'End': '2019-07-16'
},

)

and here is response

{"TotalSize": 1, "ReturnSize": 1, "ResponseMetadata": {"RequestId": "bdbdfb9e-fd84-44c7-9ab2-2f9d4cf1ecdc", "HTTPStatusCode": 200, "HTTPHeaders": {"date": "Thu, 18 Jul 2019 16:50:55 GMT", "x-amzn-requestid": "bdbdfb9e-fd84-44c7-9ab2-2f9d4cf1ecdc", "content-type": "application/x-amz-json-1.1", "content-length": "55"}, "RetryAttempts": 0}, "Tags": ["aws:createdBy"]}
Afraz Ahmad
  • 386
  • 1
  • 5
  • 20
  • Before debugging your code - can you please share if you're going to Cost Explorer - do you see your tags? Are you sure you enabled them in the billing tags? If you're running without the filter, are you getting any results? – Dvir669 Jul 24 '19 at 20:58
  • @Dvir669, I am using free tier account so not sure if they provide this functionality for free tier. and Yes I have enable tags in cost Explorer from UI. If I am running without any filter, I am getting aggregated cost. I want cost for each thing seperately – Afraz Ahmad Jul 26 '19 at 06:46
  • Hey, just to make sure we're talking about the same thing: https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/activate-built-in-tags.html - Have you enabled the custom tags you added? – Dvir669 Jul 28 '19 at 13:36
  • @Dvir669 yes, I have already Activated "Cost allocation Tags" and Activated user defined Tags – Afraz Ahmad Jul 28 '19 at 17:13
  • I'm honestly not sure what the problem is. I took your code as-is, ran it on my account (python 3.6) and it is working well - changed the tags to my own and it's working. So either the tags are misspelled, or there was still no data when you ran it on the timeframe specified. Try running it today with the current date as "End date" – Dvir669 Jul 29 '19 at 06:33

0 Answers0