Created
November 2, 2018 16:15
-
-
Save justmiles/4ae3d3148001cbead6a4e3dee392a849 to your computer and use it in GitHub Desktop.
deletes all records in a Route53 hosted zone saving a backup to your home directory
This file contains 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 | |
# | |
# purge-route53-zone.sh | |
# deletes all records in a Route53 hosted zone | |
# saving a backup to your home directory | |
# | |
# Usage: | |
# purge-route53-zone.sh HOSTED_ZONE_ID | |
# | |
# Requirements: | |
# aws-cli | |
# jq | |
# | |
HOSTED_ZONE=$1 | |
# setup workspace | |
cd `mktemp -d` | |
aws route53 list-resource-record-sets --hosted-zone-id $HOSTED_ZONE \ | |
| jq -c '.ResourceRecordSets[] | select((.Type != "NS") and (.Type != "SOA")) | {"Action":"DELETE","ResourceRecordSet":.}' > records | |
cp records ~/$HOSTED_ZONE.zone-backup | |
split -l 500 records | |
rm -rf records | |
ls | while read line; do | |
echo "purging $(wc -l $line | grep -o "[0-9]*") records" | |
record_sets=`mktemp --suffix="-$line"` | |
jq -s '{"Comment": "purging hosted zone","Changes":.}' $line > $record_sets | |
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE --change-batch=file://$record_sets | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment