Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Last active December 30, 2015 02:09
Show Gist options
  • Save cjhanks/7760337 to your computer and use it in GitHub Desktop.
Save cjhanks/7760337 to your computer and use it in GitHub Desktop.
Ec2Ls
#!/usr/bin/env python2
from sys import argv
from fnmatch import fnmatch
from boto.ec2 import connect_to_region
pattern = '*' if 1 is len(argv) else argv[1]
machines = []
for r in connect_to_region('us-east-1').get_all_instances():
for i in r.instances:
name = i.tags['Name'] if 'Name' in i.tags else ''
if fnmatch(name, pattern):
machines.append((name, i))
machines = sorted(machines, key = lambda x: x[0])
for m in machines:
print('-' * 80)
print(
'''{name:<48} {inst.launch_time}
{inst.public_dns_name}
{inst.private_dns_name}'''.format(name = m[0], inst = m[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment