Created
November 15, 2020 15:19
-
-
Save ruzickap/a3bd583ffbd59ca4cbb723eadc420017 to your computer and use it in GitHub Desktop.
Remove DNS Zone form AWS Route 53 (including all zone records)
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
ZONE_NAME="test.example.com" | |
ZONE_ID=$(aws route53 list-hosted-zones --query "HostedZones[?Name==\`${ZONE_NAME}.\`].Id" --output text) | |
aws route53 list-resource-record-sets --hosted-zone-id "${ZONE_ID}" | jq -c '.ResourceRecordSets[] | select (.Type != "SOA" and .Type != "NS")' | | |
while read -r RESOURCERECORDSET; do | |
aws route53 change-resource-record-sets \ | |
--hosted-zone-id "${CLUSTER_FQDN_ZONE_ID}" \ | |
--change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet": '"${RESOURCERECORDSET}"' }]}' \ | |
--output text --query 'ChangeInfo.Id' | |
done | |
aws route53 delete-hosted-zone --id "${ZONE_ID}" | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment