Created
December 14, 2020 07:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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