Skip to content

Instantly share code, notes, and snippets.

@shibz
Last active February 8, 2016 02:11
Show Gist options
  • Save shibz/25c4c4926e4d1ec10f7d to your computer and use it in GitHub Desktop.
Save shibz/25c4c4926e4d1ec10f7d to your computer and use it in GitHub Desktop.
Python / Boto - Get Autoscaling Group Peers
import boto.ec2.autoscale
import boto.ec2
region = "us-east-1"
instance = "i-d5ba2255"
asc = boto.ec2.autoscale.connect_to_region(region)
asi = asc.get_all_autoscaling_instances(instance_ids=[instance])
if len(asi):
group = asc.get_all_groups(names=[asi[0].group_name])[0]
ec2 = boto.ec2.connect_to_region(group.connection.region.name)
ips = map(lambda i: i.ip_address, ec2.get_only_instances(instance_ids=map(lambda i: i.instance_id, group.instances)))
else:
ips = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment