Vikas Rathore
Vikas Rathore

Reputation: 8801

AWS CLI command to get the Route 53 record set of an ELB

I have an ELB (abeXXXXXXXXXXX-12345XX.us-east-2.elb.amazonaws.com) attached to a record set in route53 (test.kubernates.com). What will the aws cli command to get the record-set attached to an elb? I want to print test.kubernates.com on the console.

I have tried passing elb endpoint to list-resource-record-sets but not getting the test.kubernates.com as the output.

Upvotes: 1

Views: 2902

Answers (3)

cheeseandcereal
cheeseandcereal

Reputation: 151

Assuming you've set up the route53 record as an alias target to the ELB, this should work:

aws route53 list-resource-record-sets --hosted-zone-id <relevant_zone_id> --query "ResourceRecordSets[?AliasTarget.DNSName == 'abeXXXXXXXXXXX-12345XX.us-east-2.elb.amazonaws.com.']"

Just substitute out the hosted zone ID for the domain you're querying, and the relevant elb domain name.

NOTE: The ELB domain name here MUST contain the trailing period (notice it ends with "amazonaws.com." in the query parameter)

Upvotes: 2

Mithun Biswas
Mithun Biswas

Reputation: 1833

You have to add a --query option to fetch the record-set. And to avoid printing last '.' character add | sed 's/.$//'

aws route53 list-resource-record-sets --hosted-zone-id <ZONE_ID>
--query "ResourceRecordSets[?ResourceRecords[?Value == 'abeXXXXXXXXXXX-12345XX.us-east-2.elb.amazonaws.com']].Name" --output text | sed 's/.$//'

Upvotes: 0

Quentin Revel
Quentin Revel

Reputation: 1478

If you are using a CNAME, you could do:

aws route53 list-resource-record-sets --output text --hosted-zone-id ZXXXXXXXXXX --query "ResourceRecordSets[?ResourceRecords[?Value == 'abeXXXXXXXXXXX-12345XX.us-east-2.elb.amazonaws.com']].Name"

Upvotes: 0

Related Questions