Listing IP addresses of instances for application load balancer in aws sdk for js

509 views Asked by At

For a classic ELB I used to call

elb.describeLoadBalancers

and received list of instances with IP addresses embedded in loadBalancerDescription following this from sdk docs http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ELB.html#describeLoadBalancers-property

Now we are switching to application load balancer so we need to switch to api version 2 http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ELBv2.html

There is the same method there describeLoadBalancers - however, for application loadbalancer there is a concept of targetGroups which includes instances.

In the response of elb.describeLoadBalancers from API version 2 there is no field like that.

How/what should I call to receive the same information like for classic loadbalancer?

2

There are 2 answers

0
Tomasz Maciejewski On

After few hours of browsing through a documentation I am pretty sure that is is not possible to retrieve instances of Application Loadbalancer by loadbalancer name. Luckily, I had also tags on my instances so I was able to use method from EC2 API describeInstances including suitable tags as filters. There is also alternative option without tags - using healthchecks.

0
Arthur Oliveira On

For those who found this question years later (like me). I discovered out a way to get the instances of an Application LoadBalancer. I used the describeTargetHealth passing the LoadBalancer arn and from that i got the informations that i needed to get to my EC2 instances such as the instance Id.

Docs: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/ELBv2.html#describeTargetHealth-property

Git that i stumbled upon and helped me a lot: https://gist.github.com/miguelmota/d748d507e18bb8d365a4948aa7187fec

One more thing be sure that you are using the ELB V2 if you are using an Application LoadBalancer.