Skip to content

Instantly share code, notes, and snippets.

@twexler
Last active August 29, 2015 14:03
Show Gist options
  • Save twexler/a63462d2a414d83f7bc9 to your computer and use it in GitHub Desktop.
Save twexler/a63462d2a414d83f7bc9 to your computer and use it in GitHub Desktop.
get all names from running instances that have a tag
import boto
ec2 = boto.connect_ec2()
ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment