Skip to content

Instantly share code, notes, and snippets.

@willpower232
Created December 13, 2019 11:10
Show Gist options
  • Save willpower232/f35519d188d9f52f1466303bb15d9a09 to your computer and use it in GitHub Desktop.
Save willpower232/f35519d188d9f52f1466303bb15d9a09 to your computer and use it in GitHub Desktop.
Create an AWS Route53 zone in a delegation set and change the NS record to match your vanity nameservers
#!/bin/bash
if [ -z "$1" ]; then
echo "Please specify domain name"
exit 1
fi
initials="WH"
delegationsetid="YOUR-DELEGATED-SET-ID"
reference="$initials$(date +%Y%m%d%H%M%S)"
# create zone in AWS and store json output
zone=$(aws route53 create-hosted-zone --delegation-set-id $delegationsetid --caller-reference $reference --name $1)
# extract the new zone ID from the json output
zoneid=$(echo "$zone" | jq .HostedZone.Id | awk -F '/' '{print $3}')
# trim the trailing quote
zoneid="${zoneid%\"}"
change="{\"ChangeBatch\":{\"Changes\":[{\"Action\":\"UPSERT\",\"ResourceRecordSet\":{\"Name\":\"$1\",\"Type\":\"NS\",\"TTL\":172800,\"ResourceRecords\":[{\"Value\":\"ns1.example.net\"},{\"Value\":\"ns2.example.net\"},{\"Value\":\"ns3.example.net\"},{\"Value\":\"ns4.example.net\"}]}}]}}"
reference="$initials$(date +%Y%m%d%H%M%S)"
changeresult=$(aws route53 change-resource-record-sets --hosted-zone-id $zoneid --cli-input-json $change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment