Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter LoadBalancer By VPC ID

I have two loadbalancers associated with two different VPC.

I am able to list all loadbalancers using AWS CLI.

Now I need to retrieve the name of the loadbalancer in a particular VPC. Is it can be done via AWS CLI ??

like image 201
schoolcoder Avatar asked Feb 09 '23 03:02

schoolcoder


1 Answers

It is true that the ELB service provides no service side filtering of results. However, you don't need to write a script to get what you want. You can use the built-in jmespath querying capability of AWSCLI.

$ aws elb describe-load-balancers --query 'LoadBalancerDescriptions[?VPCId==`vpc-12345678`]|[].LoadBalancerName'
[
    "elb1", 
    "elb2"
]
$

Should return only a list of names of load balancers that are in vpc-12345678.

like image 130
garnaat Avatar answered Feb 12 '23 12:02

garnaat