Created
December 2, 2016 23:36
-
-
Save rsalmond/25f987ff9f82852ad06e63e978ce6f4c to your computer and use it in GitHub Desktop.
Calculate unused AWS volume costs (assumes http://boto.cloudhackers.com/en/latest/getting_started.html#configuring-boto-credentials).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto.ec2 | |
from pprint import pprint | |
# https://aws.amazon.com/ebs/previous-generation/ | |
# https://aws.amazon.com/ebs/details/ | |
sizes = { | |
u'standard' : { | |
'count': 0, | |
'rate': 0.05 | |
}, | |
u'gp2' : { | |
'count': 0, | |
'rate': 0.10 | |
}, | |
u'io1' : { | |
'count': 0, | |
'rate': 0.125 | |
}, | |
u'st1' : { | |
'count': 0, | |
'rate': 0.045 | |
}, | |
u'sc1' : { | |
'count': 0, | |
'rate': 0.025 | |
} | |
} | |
if __name__ == '__main__': | |
ec2 = boto.ec2.connect_to_region('us-east-1') | |
for volume in ec2.get_all_volumes(): | |
if volume.status != u'in-use': | |
sizes[volume.type]['count'] += volume.size | |
total = 0 | |
for voltype in sizes: | |
cost = sizes[voltype]['rate'] * sizes[voltype]['count'] | |
total += cost | |
print 'type: {voltype}, monthly: ${cost}'.format(voltype=voltype, cost=cost) | |
print 'total: {}'.format(total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment