How to export Amazon Route 53 DNS Zone

To export DNS Records for a domain, you can use AWS CLI.

First, you need to make an Access key to use with AWS CLI. To configure AWS CLI, run the command

aws configure

You need to enter “Access Key ID:” and “Secret Access Key”. You can generate these in the AWS console by clicking on your name in the right top corner. Then from the drop-down menu, select “Security Credentials”. This will take you to page

https://us-east-1.console.aws.amazon.com/iam/home?region=us-east-1#/security_credentials

In the above URL us-east-1, can be changed with any region code.

AWS Security Credentials

On this page, expand “Access keys (access key ID and secret access key)”, then to create Access Key, click on the “Create New Access Key” button.

To list all DNS Zones, use the command

aws route53 list-hosted-zones --output json

From the result, you need to find the numeric id of the hosted zone.

Example

boby@sok-01:~$ aws route53 list-hosted-zones --output json
{
    "HostedZones": [
        {
            "Id": "/hostedzone/Z049372530XJK28PE5FZG",
            "Name": "serverok.in.",
            "CallerReference": "62949efe-088c-44fc-8f02-5f3f5b9fafc3",
            "Config": {
                "Comment": "My DNS Zone",
                "PrivateZone": false
            },
            "ResourceRecordSetCount": 18
        }
    ]
}
boby@sok-01:~$ 

In the above example, the zone id is Z049372530XJK28PE5FZG

To list all DNS records for the zone, use the command

aws route53 list-resource-record-sets --hosted-zone-id ZONE_ID_HERE --output json

You can use jq command to list DNS records in non json LogFormat

aws route53 list-resource-record-sets --hosted-zone-id Z049372530XJK28PE5FZG --output json | jq -jr '.ResourceRecordSets[] | "\(.Name) \t\(.TTL) \t\(.Type) \t\(.ResourceRecords[]?.Value)\n"'

In the above command, Z049372530XJK28PE5FZG is the zone id for the domain. Replace it with your DNS zone id.

Back to Route 53

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *