Skip to content

Instantly share code, notes, and snippets.

@dpvpro
Forked from earljon/aws_route53_delete.sh
Last active September 7, 2021 21:23
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 dpvpro/3793d917fea2731f0bff2235051581ec to your computer and use it in GitHub Desktop.
Save dpvpro/3793d917fea2731f0bff2235051581ec 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="ZCOKAAJ9UMS0T"
DNS_NAME="\\\\052.dev1.danwerspb.devops.rebrain.srwx.net"
RECORD_TYPE="A"
TTL=300
RESOURCE_VALUE="92.53.91.116"
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."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment