skip to Main Content

My task is to clear out our Route 53 from all the old Domain names. We have 700 records but only 200 running instances.

I have tried AWS CLI to get the EC2 instances IP address which worked fine.
I can’t seem to make a correct query on Route 53 CLI to get just the Domain Names plus the A records.

Ideally, I’d get both in a CSV format then use python to compare them.

Here is one of the Route 53 queries I tried:

aws route53 list-resource-record-sets --hosted-zone-id XXXX --output text --query 'ResourceRecordSets[*].[Name,ResourceRecords[*]]' | sed -E 's/s+/,/g' > domains.csv

2

Answers


  1. Chosen as BEST ANSWER

    I ended up using Vlookup with the two CSVs tables. I compared each IP Address in Sheet 1 with the IP address in Sheet 2. That worked for this use case as it was a one time operation.


  2. As suggested by Mark B, use python and boto3.

    This is by no means perfect and you should probably add some more filtering by type etc but it’s a start. I hope it helps you in the right direction.

    import boto3
    import json
    
    r53 = boto3.client('route53')
    
    result=r53.list_resource_record_sets(HostedZoneId="REPLACE_WITH_HOSTED_ZONE_ID")
    
    for r in result["ResourceRecordSets"]:
      output = r["Name"]
      try:
        for o in r["ResourceRecords"]:
          output += ","+o["Value"]
      except KeyError:
        pass
      print(output)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search