Skip to content

Instantly share code, notes, and snippets.

@asangal
Last active March 8, 2017 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asangal/f325623326ccda31f91ac6b717ab77b6 to your computer and use it in GitHub Desktop.
Save asangal/f325623326ccda31f91ac6b717ab77b6 to your computer and use it in GitHub Desktop.
import boto3
# Define the connection
ec2 = boto3.resource('ec2', region_name="us-west-2")
# Find all volumes
volumes = ec2.volumes.all()
# Loop through all volumes and pass it to ec2.Volume('xxx')
for vol in volumes:
#iv = ec2.Volume(str(vol.id))
formatted_tags = []
if vol.tags:
for _ in vol.tags:
tag_string = '{}({})'.format(_.get('Key'), _.get('Value'))
formatted_tags.append(tag_string)
if formatted_tags:
comma = ','
else:
comma = ''
print "created(" + str(vol.create_time) + "),availability_zone(" + str(vol.availability_zone) + "),volumeid(" + str(vol.volume_id) + "),volumetype(" + str(vol.volume_type) + "),state(" + str(vol.state) + "),size(" + str(vol.size) + "),iops(" + str(vol.iops) + "),isencrypted(" + str(vol.encrypted) + "),snapshotid(" + str(vol.snapshot_id) + "),kms_keyid(" + str(vol.kms_key_id) + "),instanceid(" + str(vol.attachments[0]['InstanceId']) + "),instancevolumestate(" + str(vol.attachments[0]['State']) + "),deleteonterminationprotection(" + str(vol.attachments[0]['DeleteOnTermination']) + "),device(" + str(vol.attachments[0]['Device']) + ")" + comma + ','.join(formatted_tags)
@asangal
Copy link
Author

asangal commented Mar 7, 2017

Version 4 fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment