Migrate Route 53 Zone to Another Zone

Frequently there is a need to migrate a Route53 DNS Zone to another zone. Here’s how one can do it.

Ensure AWS credentials you are using are correct. It’s recommended to use AWS_PROFILE to avoid connecting to a wrong AWS Account.

Save zone record sets into a json file.

text

aws route53 list-resource-record-sets --hosted-zone-id <Old Zone ID> zone.json 

Prepare the zone to be importable (and also remove SOA and NS records which already exist on the new zone)

text

jq '{Changes: [.ResourceRecordSets[] | select(.Type != "SOA" and .Type != "NS") | {Action: "CREATE", ResourceRecordSet: .}]}' zone.json > zone-change-batch.json

Load contents to a new zone

text

aws route53 change-resource-record-sets --hosted-zone-id <New Zone ID>  --change-batch file://zone-change-batch.json