Skip to content

Instantly share code, notes, and snippets.

@ruzickap
Created November 15, 2020 15:19
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 ruzickap/a3bd583ffbd59ca4cbb723eadc420017 to your computer and use it in GitHub Desktop.
Save ruzickap/a3bd583ffbd59ca4cbb723eadc420017 to your computer and use it in GitHub Desktop.
Remove DNS Zone form AWS Route 53 (including all zone records)
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