Created
February 11, 2016 23:29
-
-
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
This file contains hidden or 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 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