Last active
August 29, 2015 14:17
-
-
Save bcambel/5756d3fec6d1f1fd2ee8 to your computer and use it in GitHub Desktop.
Fetches all the instance information of a given AWS Elastic Load Balancer
This file contains hidden or 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 | |
| from boto import regioninfo | |
| from boto import ec2 | |
| ACCESS_KEY_ID = '' | |
| SECRET_ACCESS_KEY = '' | |
| elb_region = boto.regioninfo.RegionInfo( | |
| name='eu-west-1', | |
| endpoint='elasticloadbalancing.eu-west-1.amazonaws.com') | |
| elb_connection = boto.connect_elb( | |
| aws_access_key_id=ACCESS_KEY_ID, | |
| aws_secret_access_key=SECRET_ACCESS_KEY, | |
| region=elb_region) | |
| ec2_region = ec2.get_region( | |
| aws_access_key_id=ACCESS_KEY_ID, | |
| aws_secret_access_key=SECRET_ACCESS_KEY, | |
| region_name='eu-west-1') | |
| ec2_connection = boto.ec2.connection.EC2Connection( | |
| aws_access_key_id=ACCESS_KEY_ID, | |
| aws_secret_access_key=SECRET_ACCESS_KEY, | |
| region=ec2_region) | |
| LOAD_BALANCER_NAME = "" | |
| load_balancer = elb_connection.get_all_load_balancers(load_balancer_names=[LOAD_BALANCER_NAME])[0] | |
| instance_ids = [ instance.id for instance in load_balancer.instances ] | |
| reservations = ec2_connection.get_all_instances(instance_ids) | |
| instance_addresses = [ i for r in reservations for i in r.instances ] | |
| print reservations | |
| print instance_addresses | |
| for i in instance_addresses: | |
| print "INSTANCE: ",i.private_ip_address, i.private_dns_name, i.public_dns_name | |
| print dir(instance_addresses[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment