Pergunta

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)

Foi útil?

Solução 2

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

Outras dicas

The following script exports zone details in bind format from Route53. Pass over the domain name as a parameter to script. (This required awscli and jq 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"'

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.

You can export with aws api

aws route53 list-resource-record-sets --hosted-zone-id YOUR_ZONE_ID

You can export a JSON file: aws route53 list-resource-record-sets --hosted-zone-id <zone-id-here> --output json > route53-records.json

Exporting and importing is possible with https://github.com/RisingOak/route53-transfer

Based on @szentmarjay's answer above, except it shows usage and supports zone_id or zone_name. This is my fave because it's standard old school bind format, so other tools can do stuff with it.

#!/bin/bash
# r53_export

usage() {
  local cmd=$(basename "$0")
  echo -e >&2 "\nUsage: $cmd {--id ZONE_ID|--domain ZONE_NAME}\n"
  exit 1
}

while [[ $1 ]]; do
  if   [[ $1 == --id ]];     then shift; zone_id="$1"
  elif [[ $1 == --domain ]]; then shift; zone_name="$1"
  else usage
  fi
  shift
done

if [[ $zone_name ]]; then
  zone_id=$(
    aws route53 list-hosted-zones --output json \
      | jq -r ".HostedZones[] | select(.Name == \"$zone_name.\") | .Id" \
      | head -n1 \
      | cut -d/ -f3
  )
  echo >&2 "+ Found zone id: '$zone_id'"
fi
[[ $zone_id ]] || usage

aws route53 list-resource-record-sets --hosted-zone-id $zone_id --output json \
  | jq -jr '.ResourceRecordSets[] | "\(.Name) \t\(.TTL) \t\(.Type) \t\(.ResourceRecords[]?.Value)\n"'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top