迁移账号

AWS Route53 跨账号迁移_boto3

目标AWS 接受域名

AWS Route53 跨账号迁移_route53_02

  • 新增托管域名生成NS地址

AWS Route53 跨账号迁移_route53_03



授权IAM

创建一个AK , 授权route53全部权限

建两个用户

useradd old-aws
useradd new-aws
  • 1.
  • 2.

给两个账号添加不同ak

su - old-aws
aws configure
  • 1.
  • 2.


Route53 记录导出脚本

import boto3
import json
import argparse

# 创建命令行参数解析器
parser = argparse.ArgumentParser(description='Export Route 53 records for a given hosted zone.')
parser.add_argument('--zone', required=True, help='The hosted zone ID')

# 解析命令行参数
args = parser.parse_args()

# 创建 Route 53 客户端
client = boto3.client('route53')

# 获取指定托管区域的所有记录
response = client.list_resource_record_sets(HostedZoneId=args.zone)

# 提取主域名
zone_info = client.get_hosted_zone(Id=args.zone)
main_domain = zone_info['HostedZone']['Name']

# 过滤掉 NS 和 SOA 记录
filtered_records = [record for record in response['ResourceRecordSets'] if record['Type'] not in ['NS', 'SOA']]

# 以主域名命名的 JSON 文件
file_name = f'{main_domain}records.json'

# 保存记录到 JSON 文件
with open(file_name, 'w') as f:
    json.dump(filtered_records, f, indent=4)

print(f"记录已导出到 {file_name}")
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
python3 route53_export.py --zone Z0621xxxx
  • 1.


Route53 记录导入新托管域名

import boto3
import json
import argparse

# 创建命令行参数解析器
parser = argparse.ArgumentParser(description='Import Route 53 records to a given hosted zone.')
parser.add_argument('--zone', required=True, help='The hosted zone ID')
parser.add_argument('--file', required=True, help='The JSON file containing records')

# 解析命令行参数
args = parser.parse_args()

# 创建 Route 53 客户端
client = boto3.client('route53')

# 读取记录从指定的 JSON 文件
with open(args.file, 'r') as f:
    records = json.load(f)

# 批量创建记录
change_batch = {
    'Changes': [{'Action': 'CREATE', 'ResourceRecordSet': record} for record in records]
}

response = client.change_resource_record_sets(
    HostedZoneId=args.zone,
    ChangeBatch=change_batch
)

print("记录已导入,变更请求 ID:", response['ChangeInfo']['Id'])
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
python3 route53_import.py  --zone   Z0851xxxxx --file test.com.records.json
  • 1.


替换新的dns服务器记录

AWS Route53 跨账号迁移_route53_04