Skip to content

Instantly share code, notes, and snippets.

@earljon
Created August 15, 2017 08:58
Show Gist options
  • Save earljon/8579429f90c3480c06eb2bc952255987 to your computer and use it in GitHub Desktop.
Save earljon/8579429f90c3480c06eb2bc952255987 to your computer and use it in GitHub Desktop.
Delete a Route 53 Record Set in AWS CLI
#!/bin/sh
# NOTE:
# Make sure that the value of Name, Type, TTL are the same with your DNS Record Set
HOSTED_ZONE_ID=<YOUR_HOSTED_ZONE_ID>
RESOURCE_VALUE=<YOUR_DNS_RESOURCE_VALUE-ex:IP or dns>
DNS_NAME=<YOUR_DNS_NAME-ex: subdomain.domain.com>
RECORD_TYPE=<DNS_RECORD_TYPE-ex: A, CNAME>
TTL=<TTL_VALUE>
JSON_FILE=`mktemp`
(
cat <<EOF
{
"Comment": "Delete single record set",
"Changes": [
{
"Action": "DELETE",
"ResourceRecordSet": {
"Name": "$DNS_NAME.",
"Type": "$RECORD_TYPE",
"TTL": $TTL,
"ResourceRecords": [
{
"Value": "${RESOURCE_VALUE}"
}
]
}
}
]
}
EOF
) > $JSON_FILE
echo "Deleting DNS Record set"
aws route53 change-resource-record-sets --hosted-zone-id ${HOSTED_ZONE_ID} --change-batch file://$JSON_FILE
echo "Deleting record set ..."
echo
echo "Operation Completed."
@lgb861213
Copy link

lgb861213 commented Jun 2, 2024

I �use it delete the route hosted zone ,but it failed. so I use the aws_route53_delete.py and delele success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment