Exporting DNS zonefile from Amazon Route 53

casparjespersen picture casparjespersen · Dec 2, 2013 · Viewed 45.2k times · Source

I would like to export a DNS zonefile from my Amazon Route 53 setup. Is this possible, or can zonefiles only be created manually? (e.g. through http://www.zonefile.org/?lang=en)

Answer

Szentmarjay Tibor picture Szentmarjay Tibor · Jan 29, 2018

The following script exports zone details in bind format from Route53. Pass over the domain name as a parameter to script. (This required awscli to be installed and configured.)

#!/bin/bash

zonename=$1
hostedzoneid=$(aws route53 list-hosted-zones --output json | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3)
aws route53 list-resource-record-sets --hosted-zone-id $hostedzoneid --output json | jq -jr '.ResourceRecordSets[] | "\(.Name) \t\(.TTL) \t\(.Type) \t\(.ResourceRecords[].Value)\n"'