Obtaining tags from AWS instances with boto

后端 未结 4 1613
有刺的猬
有刺的猬 2020-12-31 02:19

I\'m trying to obtain tags from instances in my AWS account using Python\'s boto library.

While this snippet works correctly bringing all tags:

    t         


        
4条回答
  •  醉话见心
    2020-12-31 03:18

    For boto3 you will need to do this.

    import boto3
    ec2 = boto3.resource('ec2')
    vpc = ec2.Vpc('')
    instance_iterator = vpc.instances.all()
    
    for instance in instance_iterator:
        for tag in instance.tags:
            print('Found instance id: ' + instance.id + '\ntag: ' + tag)
    

提交回复
热议问题