Created
December 11, 2013 17:14
-
-
Save kryptek/7914531 to your computer and use it in GitHub Desktop.
Retrieve an EC2 Load Balancers instances and their health status using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto | |
import sys | |
ec2 = boto.connect_ec2() | |
elb = boto.connect_elb() | |
load_balancer = elb.get_all_load_balancers(load_balancer_names=[sys.argv[1]])[0] | |
health = load_balancer.get_instance_health() | |
instances = ec2.get_only_instances(instance_ids=[instance.id for instance in load_balancer.instances]) | |
headers = ['Instance ID', 'Address', 'Flavor', 'Status'] | |
row_format = "{:>15}" * (len(headers) + 1) | |
print row_format.format("",*headers) | |
for instance in instances: | |
print row_format.format('',*[instance.id, instance.ip_address, instance.instance_type, [str(i.state) for i in health if i.instance_id == instance.id ][0]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment