Backing up your route53 zone configuration with the aws CLI

In a previous post, I discussed using the Kubernetes external-dns project to manage DNS changes. Prior to rolling it out, I needed a way to backup each zone prior to external-dns modifying it. I also wanted this to occur each time a commit occurred that resulted in a DNS change. This turned out to be super easy to do with the aws CLI. To export all records in a zone, you will first need to locate the zone id. You can get this with the “list-hosted-zones” command:

$ aws --profile me route53 list-hosted-zones

    "HostedZones": [
            "Id": "/hostedzone/XXXXXXXXXXX",
            "Name": "",
            "CallerReference": "XXXXXXXX",
            "Config": {
                "Comment": "HostedZone created by Route53 Registrar",
                "PrivateZone": false
            "ResourceRecordSetCount": 2

Once you have the id you can export the records with the “list-resource-record-sets” command:

$ aws --profile me route53 list-resource-record-sets --hosted-zone-id iXXXXXXXXXXX

This will produce a JSON object which you can stash in a safe location. If something were to happen to your route53 zone, you can use the “change-resource-record-sets” command along with the last JSON object to restore it to a known state. Nice!

This article was posted by on 2020-01-30 00:00:00 -0500 -0500