Skip to content

Instantly share code, notes, and snippets.

@j-un
Created December 14, 2020 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-un/ccfda2925e73853439a13e91b0c04a20 to your computer and use it in GitHub Desktop.
Save j-un/ccfda2925e73853439a13e91b0c04a20 to your computer and use it in GitHub Desktop.
Create resource record sets for migrating a hosted zone to a different AWS account.
#!/bin/bash
# Create resource record sets for migrating a hosted zone to a different AWS account.
# Ref: https://docs.aws.amazon.com/en_us/Route53/latest/DeveloperGuide/hosted-zones-migrating.html
#
# Usage: aws route53 list-resource-record-sets --hosted-zone-id XXXXXXXXXXXXXX | bash migrate-r53-hosted-zone.sh
#
if [ -z $(command -v jq) ] ;then
echo "command not found: jq"
exit 1
fi
ZONE=$(cat -)
COUNT=$(echo $ZONE | jq ".ResourceRecordSets | length")
(echo '{ "Comment": "", "Changes": ['
for RECORDSET in $( seq 0 $(($COUNT - 1)) ); do
OBJECT=$(echo $ZONE | jq ".ResourceRecordSets | {\"Action\": \"CREATE\"} + {\"ResourceRecordSet\": .[$RECORDSET]}")
TYPE=$(echo $OBJECT | jq -r ".ResourceRecordSet.Type")
if [ $TYPE != "NS" -a $TYPE != "SOA" ]; then
if [ $RECORDSET != 0 ]; then
echo ','
fi
echo $OBJECT
fi
done
echo '] }') | jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment