Guest User

Untitled

a guest
Apr 25th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #!/bin/bash
  2. # AWS route53 Delete all hosted zones.
  3. # Requires aws cli, jq
  4. # chmod u+x ~/aws-route53-delete-hosted-zones.sh
  5.  
  6. # AWS profile to use.
  7. PROFILE="default"
  8.  
  9. # Loop through each Hosted Zone.
  10. while read id
  11. do
  12.  
  13. # Output Hosted Zone ID
  14. echo "$id"
  15.  
  16. # List all existing Record Sets.
  17. aws route53 list-resource-record-sets --hosted-zone-id "$id" --profile="$PROFILE" | jq -c '.ResourceRecordSets[]' | while read -r resourcerecordset ; do
  18.  
  19. read -r name type <<<$(echo $(jq -r '.Name,.Type' <<<"$resourcerecordset"))
  20.  
  21. # Output record type and name
  22. echo "$type : $name"
  23.  
  24. # Delete any record that is of type NS or SOA.
  25. if [ $type != "NS" -a $type != "SOA" ]; then
  26. aws route53 change-resource-record-sets \
  27. --hosted-zone-id "$id" \
  28. --change-batch '{"Changes":[{"Action":"DELETE","ResourceRecordSet":'"$resourcerecordset"'}]}' \
  29. --output text \
  30. --profile="$PROFILE"
  31. fi
  32.  
  33. done;
  34.  
  35. # Delete the Hosted Zone
  36. aws route53 delete-hosted-zone --id "$id" --profile="$PROFILE"
  37.  
  38. 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