Skip to content

Instantly share code, notes, and snippets.

@stevear22
Created February 11, 2016 23:29
Show Gist options
  • Save stevear22/e4cb0fc060efe1643a54 to your computer and use it in GitHub Desktop.
Save stevear22/e4cb0fc060efe1643a54 to your computer and use it in GitHub Desktop.
AWS (Boto3) find EC2 instances and change tags on attached EBS volumes to match
import boto3
region_list = ['us-west-1', 'us-west-2']
for region in region_list:
print 'REGION:', region
ec2 = boto3.resource('ec2', region)
for instance in ec2.instances.all():
print ' instance:', instance
ec2tags = instance.tags
print ' tags:', ec2tags
for volume in instance.volumes.all():
print ' volume:', volume
# Create tags on volume if they don't match the instance
if volume.tags != ec2tags:
print '\033[93m' + 'Tags don\'t match, updating'
volume.create_tags(DryRun=False, Tags=ec2tags)
print ' tags:', volume.tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment