Skip to content

Instantly share code, notes, and snippets.

@samermassoud
Last active November 16, 2022 05:33
Show Gist options
  • Save samermassoud/5906ebfdd44d3af65b54213796f906ea to your computer and use it in GitHub Desktop.
Save samermassoud/5906ebfdd44d3af65b54213796f906ea to your computer and use it in GitHub Desktop.
Dynamic DNS - AWS Route 53
@reboot root /path/to/file/update-dns-aws.sh <hosted-zone-id> <dns>
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:GetHostedZone",
"route53:ChangeResourceRecordSets",
"route53:ListResourceRecordSets"
],
"Resource": "arn:aws:route53:::hostedzone/<target_host_zone_id>"
},
{
"Effect": "Allow",
"Action": [
"route53:ListHostedZones"
],
"Resource": "*"
}
]
}
#!/bin/bash
HOSTED_ZONE_ID=$1
DOMAIN_NAME=$2
PUBLIC_RECORD=$3
if [ -z $PUBLIC_RECORD ]
then
PUBLIC_RECORD=$DOMAIN_NAME.
else
PUBLIC_RECORD=$PUBLIC_RECORD.$DOMAIN_NAME.
fi
IP=$(curl -s https://checkip.amazonaws.com)
echo Found IP=$IP
read -r -d '' R53_ARECORD_JSON << EOM
{
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$PUBLIC_RECORD",
"Type": "A",
"TTL": 300,
"ResourceRecords": [
{
"Value": "$IP"
}
]
}
}
]
}
EOM
echo About to execute change
echo "$R53_ARECORD_JSON"
R53_ARECORD_ID=`aws route53 change-resource-record-sets \
--hosted-zone-id $HOSTED_ZONE_ID \
--change-batch "$R53_ARECORD_JSON" \
--query '[ChangeInfo.Comment, ChangeInfo.Id, ChangeInfo.Status, ChangeInfo.SubmittedAt]' \
--output text`
#echo $R53_ARECORD_ID
#aws route53 wait resource-record-sets-changed --id $R53_ARECORD_ID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment