Skip to content

Instantly share code, notes, and snippets.

@brannn
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save brannn/232da119b3aa74f24901 to your computer and use it in GitHub Desktop.

Select an option

Save brannn/232da119b3aa74f24901 to your computer and use it in GitHub Desktop.
Get running instances behind ELB by 'Release' tag
#!/usr/bin/env python
import argparse
import boto.ec2.elb
import boto.ec2
parser = argparse.ArgumentParser(description="Get ELB instances by release tag")
parser.add_argument("-region", "--region",
metavar="region",
dest="region",
required=True,
help="AWS Region")
parser.add_argument("-release", "--release",
metavar="release",
dest="release",
required=True,
help="Release")
args = parser.parse_args()
ec2conn = boto.ec2.connect_to_region(args.region)
print "Filtering running instances for Release tag => " + args.release
reservations = ec2conn.get_all_instances(filters={"tag:Release": args.release})
instances = [i for r in reservations for i in r.instances]
addresses = [i.private_ip_address for r in reservations for i in r.instances]
instance_ids = []
for instance, address in zip(instances, addresses):
print instance, address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment