Displaying EC2 Instance name using Boto 3 Displaying EC2 Instance name using Boto 3 python-3.x python-3.x

Displaying EC2 Instance name using Boto 3


There may be other ways. But from your code point of view, the following should work.

>>> for i in vpc.instances.all():...   for tag in i.tags:...     if tag['Key'] == 'Name':...       print tag['Value']

One liner solution if you want to use Python's powerful list comprehension:

inst_names = [tag['Value'] for i in vpc.instances.all() for tag in i.tags if tag['Key'] == 'Name']print inst_names


In AWS EC2 an instance is tagged with a Name tag.

In order to get the value of the Name tag for a given instance, you need to query the instance for that tag:

See Obtaining tags from AWS instances with boto