hey
hey

Reputation: 3262

aws cli elb / elbv2 - How to filter load balancers by DNSName?

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.

Upvotes: 2

Views: 6960

Answers (2)

eramm
eramm

Reputation: 241

You can use a query and jmespath

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

Upvotes: 1

kerma
kerma

Reputation: 2791

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'

Upvotes: 5

Related Questions