Exporting DNS zonefile from Amazon Route 53

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)


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"'

It's not possible yet. You'll have to use the API's ListResourceRecordSets and build the zonefile yourself.


As stated in the comment, the cli53 is a great tool to interact with Route 53 using the command line interface.

First, configure your account keys in ~/.aws/config file:

[default]
aws_access_key_id = AK.....ZP
aws_secret_access_key = 8j.....M0

Then, use the export command:

$ cli53 export --full --debug example.com > example.com.zone 2> example.com.zone.log

Verify the example.com.zone file after export to make sure that everything is exported correctly.

You can import the zone lately:

$ cli53 import --file ./example.com.zone example.com

And if you want to transfer the Route53 zone from one AWS account to another, you can use the profile option. Just add two named accounts to the ~/.aws/config file and reference them with the profile property during export and import. You can even pipe these two commands.