Skip to content

Instantly share code, notes, and snippets.

@torufurukawa
Created February 14, 2013 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torufurukawa/4949837 to your computer and use it in GitHub Desktop.
Save torufurukawa/4949837 to your computer and use it in GitHub Desktop.
Get running instance names on EC2
import boto.ec2
c = boto.ec2.connect_to_region('ap-northeast-1',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
reservations = c.get_all_instances()
instances = [item for sublist in reservations for item in sublist.instances]
for instance in instances:
if instance.state != 'running':
continue
print instance.tags.get('Name')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment