Skip to content

Instantly share code, notes, and snippets.

@porjo
Last active February 15, 2024 14:19
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save porjo/7447463ce0d14f212e58f9eabad77090 to your computer and use it in GitHub Desktop.
Save porjo/7447463ce0d14f212e58f9eabad77090 to your computer and use it in GitHub Desktop.
Export route53 records to CSV

Retrieve hosted zones with aws route53 list-hosted-zones then enter the zone Id below:

aws route53 list-resource-record-sets --hosted-zone-id "/hostedzone/xxxxxxxxxxx" | \
   jq -r '.ResourceRecordSets[] | [.Name, .Type, (.ResourceRecords[]? | .Value), .AliasTarget.DNSName?]  | @tsv'
@swoodford-clear
Copy link

swoodford-clear commented Dec 18, 2023

this solution handles ALIAS records which are exported as A records but invalid to import anywhere but AWS

  • also replaces extraordinarily high TTL values with 86400 which is the highest possible, and null TTL values with 300
  • any other null values are exported as "unknown" for troubleshooting later
  • exports as tab separated for BIND format that can be imported elsewhere
profile=example
hosted_zone="HOSTEDZONEID"

aws route53 list-resource-record-sets --profile $profile --hosted-zone-id $hosted_zone --output json | \
jq -r '.ResourceRecordSets[] | "\(.Name // "unknown")\t\((if .TTL > 86400 then 86400 else .TTL // 300 end))\tIN\t\((if .AliasTarget.DNSName then "CNAME" else .Type // "unknown" end))\t\(.ResourceRecords[]?.Value // .AliasTarget.DNSName // "unknown")"'

@rikwouters
Copy link

rikwouters commented Feb 15, 2024

Thank you!

Note: I ran a few of these aws/jq commands in a Microsoft Windows shell and got errors like

'[.Name' is not recognized as an internal or external command, operable program or batch file.

Using double quotes makes it work.

list-resource-record-sets --hosted-zone-id "/hostedzone/ZXXXXXXXXXXXXX" | jq -r ".ResourceRecordSets[] | [.Name, .Type, (.ResourceRecords[]? | .Value), .AliasTarget.DNSName?] | @tsv" > abc.tsv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment