Created
September 9, 2019 11:48
-
-
Save ttor/b44d671ba4dc770b5d241473a0df39cb to your computer and use it in GitHub Desktop.
Copy tags from EC2 instance to attached EBS volume
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
#adapted from https://gist.github.com/mlapida/931c03cce1e9e43f147b | |
import boto3 | |
tags_to_use = ['Owner'] | |
def copy_tags(): | |
instances = boto3.resource('ec2').instances.all() | |
for instance in instances: | |
tags = instance.tags | |
to_tag = [t for t in tags if t['Key'] in tags_to_use] | |
for vol in instance.volumes.all(): | |
print(vol.id, instance.id,to_tag) | |
if to_tag: | |
vol.create_tags(Tags=to_tag) | |
copy_tags() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment