Skip to content

Instantly share code, notes, and snippets.

@porjo
Last active February 12, 2025 02:08
Show Gist options
  • 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'
@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

@billflu
Copy link

billflu commented Feb 5, 2025

Export all your hosted zones to both json and CSV.

for zone in `aws route53 list-hosted-zones --query 'HostedZones[*].Id' --output text`
do
	echo $zone
	records=`aws route53 list-resource-record-sets --hosted-zone-id $zone --output json`
	echo "$records" | jq -r '["Name", "Type", "Value"], (.ResourceRecordSets[] | [.Name, .Type, (.ResourceRecords | select(. != null) | map(.Value) | join(" ")), (.AliasTarget.DNSName? | select(. != null))]) | @csv' > ${zone:12}.csv
	echo "$records" > ${zone:12}.txt
done

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