2
votes

I need to find out the arn of a load balancer. The only information I have is the DNS name.

It seems to be easy to extract the region from the DNS name, as it is part of it:

MyElbName.us-west-2.elb.amazonaws.com

Filtering, though, does not work:

# aws elbv2 describe-load-balancers --filters "Name=DNSName,Values=MyElbName-1190680708.us-west-2.elb.amazonaws.com"
usage: aws [options]   [ ...] [parameters]
To see help text, you can run:

  aws help
  aws  help
  aws   help

Unknown options: --filters, Name=DNSName,Values=MyElbName-1190680708.us-west-2.elb.amazonaws.com --region "us-west-2"
#

Is the --filters option maybe just not available in the elbv2 namespace? I have the same issue in the elb namespace, but in elb, even the region is not available.

2
Before trying to get the filtering to work, can you see the desired Load Balancer in the console? You will only be able to view Load Balancers that belong to your own AWS Account. Also, please note that there is no --filter option for this command. See: describe-load-balancers — AWS CLI Command ReferenceJohn Rotenstein
Thanks @JohnRotenstein. Yes, I can see the Load Balancer in the console, if I use elbv2 and specify my region. - Thanks for the information about the lack of availability of that parameter; I did not find the information anywhere. I might need to filter by jq or so...hey

2 Answers

3
votes

There is no --filters option for describe-load-balancers. You could use jq:

aws elbv2 describe-load-balancers | \
   jq '.LoadBalancers[] | 
       select(.DNSName == "your-dns-name.elb.amazonaws.com") | 
       .LoadBalancerArn'
0
votes

You can use a query and jmespath

aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,LoadBalancerArn]' --output text