Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # AWS route53 Delete all hosted zones.
- # Requires aws cli, jq
- # chmod u+x ~/aws-route53-delete-hosted-zones.sh
- # AWS profile to use.
- PROFILE="default"
- # Loop through each Hosted Zone.
- while read id
- do
- # Output Hosted Zone ID
- echo "$id"
- # List all existing Record Sets.
- aws route53 list-resource-record-sets --hosted-zone-id "$id" --profile="$PROFILE" | jq -c '.ResourceRecordSets[]' | while read -r resourcerecordset ; do
- read -r name type <<<$(echo $(jq -r '.Name,.Type' <<<"$resourcerecordset"))
- # Output record type and name
- echo "$type : $name"
- # Delete any record that is of type NS or SOA.
- if [ $type != "NS" -a $type != "SOA" ]; then
- aws route53 change-resource-record-sets \
- --hosted-zone-id "$id" \
- --change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet":'"$resourcerecordset"'}]}' \
- --output text \
- --profile="$PROFILE"
- fi
- done;
- # Delete the Hosted Zone
- aws route53 delete-hosted-zone --id "$id" --profile="$PROFILE"
- done <<< "`aws route53 list-hosted-zones --profile="$PROFILE" | jq -r '.HostedZones | map(.Id | split("/")[2]) | join("\n")'`"
Add Comment
Please, Sign In to add comment