Migrate Route 53 Zone to Another Zone
Contents
Frequently there is a need to migrate a Route53 DNS Zone to another zone. Here’s how one can do it.
Prerequisites
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
Save zone record sets into a json file.
aws route53 list-resource-record-sets --hosted-zone-id <Old Zone ID> zone.json
Convert zone file to a change
Prepare the zone to be importable (and also remove SOA and NS records which already exist on the new zone)
jq '{Changes: [.ResourceRecordSets[] | select(.Type != "SOA" and .Type != "NS") | {Action: "CREATE", ResourceRecordSet: .}]}' zone.json > zone-change-batch.json
Restore Zone
Load contents to a new zone
aws route53 change-resource-record-sets --hosted-zone-id <New Zone ID> --change-batch file://zone-change-batch.json