Created
September 4, 2020 06:04
-
-
Save ts1/28d6044500074324b1860bfcae2e3187 to your computer and use it in GitHub Desktop.
Dynamic DNS update using AWS Lightsail Domain API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -eo pipefail | |
| DOMAIN=example.com | |
| ENTRY=examplehost | |
| #LINE_TOKEN=xxxxxx | |
| get_ip() { | |
| curl -s 'https://api.ipify.org' | |
| } | |
| get_dns() { | |
| aws lightsail get-domain --domain-name=$DOMAIN | | |
| jq -r ".domain.domainEntries[] | select(.name == \"$ENTRY.$DOMAIN\") | .target" | |
| } | |
| get_id() { | |
| aws lightsail get-domain --domain-name=$DOMAIN | | |
| jq -r ".domain.domainEntries[] | select(.name == \"$ENTRY.$DOMAIN\") | .id" | |
| } | |
| update() { | |
| local ID=$1 | |
| local IP=$2 | |
| aws lightsail update-domain-entry --domain-name $DOMAIN --domain-entry id=$ID,name=$ENTRY.$DOMAIN,type=A,target=$IP | |
| } | |
| IP=`get_ip` | |
| DNS=`get_dns` | |
| if [ "$IP" != "$DNS" ]; then | |
| echo "Updating $ENTRY.$DOMAIN from $DNS to $IP" | |
| ID=`get_id` | |
| update $ID $IP | |
| ## Send a notification | |
| #curl -H "Authorization: Bearer $LINE_TOKEN" \ | |
| # -d message="$ENTRY.$DOMAIN changed IP to $IP" \ | |
| # https://notify-api.line.me/api/notify | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment