Manzoor
Manzoor

Reputation: 85

How to query AWS to get ELB names and attached instances to that using python boto modules?

I am trying retrieve the ELB names and the attached instances ids using python boto modules.

{
    import boto

    conn = boto.connect_elb()
    conn.get_all_load_balancers()
}

Gives only load-balancer names now how can i retrieve the Instance-ids attached to the load-balancer ?

Upvotes: 0

Views: 1080

Answers (1)

Vor
Vor

Reputation: 35109

conn.get_all_load_balancers() - returns a list of elbs objects. Each elb object has a parameter instances that will show you attached instances. And from there you can get their Id's.
If you want to find elb by name, then you need to filter first loop.

So something like this should work (Thanks @Frédéric Henri for update):

import boto

conn = boto.connect_elb()
elbs = conn.get_all_load_balancers(load_balancer_names=['MY-ELB-NAME'])[0]
instances = [inst.id for elb in elbs for inst in elb.instances]

Upvotes: 3

Related Questions