Obtaining tags from AWS instances with boto

后端 未结 4 1612
有刺的猬
有刺的猬 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:21

    Try something like this:

    import boto.ec2
    
    conn = boto.ec2.connect_to_region('us-west-2')
    # Find a specific instance, returns a list of Reservation objects
    reservations = conn.get_all_instances(instance_ids=['i-xxxxxxxx'])
    # Find the Instance object inside the reservation
    instance = reservations[0].instances[0]
    print(instance.tags)
    

    You should see all tags associated with instance i-xxxxxxxx printed out.

提交回复
热议问题