AWS Logo
Menu
Migrate a hosted zone to a different AWS account in few seconds!!

Migrate a hosted zone to a different AWS account in few seconds!!

Transferring a hosted zone between AWS accounts might sound like a daunting task, but it doesn't have to be! This guide shows you how to migrate your DNS configurations swiftly and effortlessly. With the right approach, you can replicate your hosted zone's records in a new account without downtime, ensuring seamless domain management. Whether you're restructuring your AWS environment or transferring ownership, these steps will make the process quick and efficient.

Published Nov 26, 2024
Migrating a hosted zone from one AWS account to another involves creating a new hosted zone in the target account, replicating the DNS records, and updating the domain's nameservers. Here's a step-by-step guide for manual and automated steps.

-- Manual Steps --

In this manual process, will guide you through migrating a hosted zone using the AWS CLI.

1. Export DNS Records from the Source Account

  1. Install AWS CLI if not already installed.
  2. Use the following command to export the DNS records from the hosted zone in the source account:
3. Save the output file (dns-records.json), which contains all DNS records.

2. Create a New Hosted Zone in the Target Account

  1. Log in to the target AWS account.
  2. Navigate to Route 53 and create a new hosted zone with the same domain name.
  3. Note the new hosted zone ID and nameservers assigned to the zone.

3. Import DNS Records to the Target Account

  1. Use the exported dns-records.json to replicate the records.
  2. Transform the JSON file to match the change-resource-record-sets API format if needed. An example format looks like this:
3. Import the records to the new hosted zone:

4. Update the Domain's Nameservers

  1. Go to your domain registrar (e.g., AWS Route 53, GoDaddy, Namecheap).
  2. Replace the nameservers with the ones provided in the new hosted zone.
  3. Wait for the DNS propagation, which can take up to 48 hours.

5. Verify the Migration

  1. Use tools like DNS Checker to ensure the records are correctly propagating.
  2. Confirm that the DNS records are functional and resolving to the expected values.

Tips

  • Avoid downtime: Keep both hosted zones active until propagation is complete.
  • Delegate permissions: If you need cross-account access, consider using AWS Resource Access Manager (RAM) or an IAM role for temporary access.
  • Automate the process: Use tools like Terraform or Route 53's APIs for larger migrations.


-- Automated Steps --

Here’s a Python script using boto3 (AWS SDK for Python) to automate the transformation and migration of DNS records between AWS accounts. This script will:
  1. Export DNS records from the source account.
  2. Transform them into the format required for importing.
  3. Import the records into the target account.

Prerequisites

  1. Install the required libraries:
2. Set up AWS CLI profiles for both accounts:
  • Source account: aws configure --profile source_account
  • Target account: aws configure --profile target_account
3. Save the python script as migrate_dns.py

How to Use

  1. Replace source-hosted-zone-id and target-hosted-zone-id with the respective hosted zone IDs. Also replace profiles if you have created differently.
  2. Run the script:

Key Notes

  • SOA and NS records are skipped: These are automatically managed by AWS.
  • TTL fallback: If a record lacks a TTL, a default value of 300 seconds is applied.
     

Comments