Friday, 25 January 2019

Getting snapshot cost based on tags

I am trying to use cost explorer API using boto3. I am trying to get cost for EC2 snapshots. These snapshots have custom tags associated with them. What I am trying to achieve is cost of snapshots which have a particuar tag.

I have written the following script:

import boto3
client = boto3.client('ce')
response = client.get_cost_and_usage(
    TimePeriod={
        'Start': '2019-01-10',
        'End': '2019-01-15'
    },
    Metrics=['BLENDED_COST','USAGE_QUANTITY','UNBLENDED_COST'],
    Granularity='MONTHLY',
    Filter={
        'Dimensions': {
                       'Key':'USAGE_TYPE',
                       'Values': ['APN1-EBS:SnapshotUsage']
                      }
     }
)

This gives me the cost. But this is total cost for the snapshot usage.i.e. for all the volumes. Is there any way to filter based on tags on the volumes?



from Getting snapshot cost based on tags

No comments:

Post a Comment