Last active
October 25, 2018 15:12
-
-
Save rashidcmb/dce152c68aaf5c3943164721285f53e1 to your computer and use it in GitHub Desktop.
This simple python script will update the Name tags of EBS volume with attached EC2 instance Name tag.
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 boto3 | |
ec2 = boto3.resource('ec2',region_name='us-east-1') | |
for volume in ec2.volumes.all(): | |
vol = ec2.Volume(volume.id) | |
ebsId = volume.id | |
for v in vol.attachments: | |
ec2Id = v["InstanceId"] | |
ec2instance = ec2.Instance(ec2Id) | |
if ec2Id is not None: | |
for tags in ec2instance.tags: | |
if tags["Key"] == 'Name': | |
instancename = tags["Value"] | |
print(instancename) | |
volume.create_tags(Tags=[{'Key': 'Name','Value': instancename},]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment