This TypeScript script is designed to automate the process of exporting DNS records from an AWS Route53 hosted zone in one AWS account and preparing it for importing into another AWS Route53 hosted zone, possibly in a different AWS account. It filters out NS and SOA records and saves the remaining records in a JSON file. The script is written based on the AWS Route53 developer guide for migrating hosted zones, as of the date 2023-08-29. More information can be found here.
- Node.js (version 18.x or above) and npm
- AWS CLI (version 2.x)
Before running the script, ensure that you have configured the AWS CLI profiles for both the source and target AWS accounts.
-
Configure the Source AWS Account
Run
aws configure --profile old-aws-account-profileand follow the prompts to input your AWS Access Key ID, Secret Access Key, default region, and output format. -
Configure the Target AWS Account
Run
aws configure --profile new-aws-account-profileand follow the prompts.
- Install Node.js dependencies by running `npm install` in the directory where the script is located.
-
Run the script by executing
npm start. -
You will be prompted to select the AWS profile for the source AWS account. Choose the profile you set up for the source account (e.g.,
old-aws-account-profile). -
Next, you will be prompted to choose a hosted zone from the source AWS account. The script will list all available hosted zones.
-
The script will then process the records, filter out NS and SOA records, and save them to a JSON file named
{HostedZoneID}-migrated.json. -
You will then be prompted to select the AWS profile for the target AWS account. Choose the profile you set up for the target account (e.g.,
new-aws-account-profile). -
Finally, you'll be prompted to select a hosted zone in the target AWS account where you'd like to import the DNS records.
After running the script, there are few additional steps (Steps 8, 9 and 10) you might need to follow as outlined in the AWS Route53 Developer Guide for migrating hosted zones:
⚠️ Failure to follow these steps can result in the domain becoming unavailable.
If you encounter issues related to empty ResourceRecords in your JSON, ensure your AWS SDK is up-to-date. The script automatically omits empty ResourceRecords fields.