Engineering

Moving Record Sets in Route53

Amazon makes it easy to import a zone file into Route53 through their GUI, but not so easy to export. Thankfully, you can export using the aws CLI, transform that result, and easily import using the GUI.

  • Find the hosted zone to export:
1
aws route53 list-hosted-zones
  • Save this ruby to parse the output. You can tune this script to pick the types of records you’d like or to transform the record name:
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env ruby

require 'json'
json = $stdin.read
records_to_print = ['A']
transform_domain = ['grandrounds.com', 'grandroundshealth.com'] # old, new

JSON.parse(json)['ResourceRecordSets'].each do |rs|
  rs['ResourceRecords'].each do |r|
    print "#{rs['Name'].gsub(transform_domain[0], transform_domain[1])} #{rs['TTL']} IN #{rs['Type']} #{r['Value']}\n" if records_to_print.rindex(rs['Type'])
  end
end
  • Export the zone json, pipe it to the ruby parser, and capture the results on your clipboard:
1
aws route53 list-resource-record-sets --hosted-zone-id /hostedzone/Z2DIRTC0AKGD29 | ./zone-parse.rb | xsel -ib
  • Finally, import the zone file snippet

Route 53 Image #2 Route 53 Image #1