Build your own DynDNS with AWS Lambda and systemd.times

dns.sh

#!/bin/bash
myHostname=my.example.com.
mySharedSecret=abcd
myAPIURL=abcd.execute-api.eu-central-1.amazonaws.com/prod
# Call the API in get mode to get the IP address
myIP=`curl -s -X GET --retry 3 http://whatismyip.akamai.com/`
# Build the hashed token
myHash=`echo -n $myIP$myHostname$mySharedSecret | /usr/bin/core_perl/shasum -a 256 | awk '{print $1}'`
# Call the API in set mode to update Route 53
curl -s -q --retry 3 "https://$myAPIURL?mode=set&hostname=$myHostname&hash=$myHash"
echo

/etc/systemd/system/dns.service

[Unit]
Description=DNS service

[Service]
Type=oneshot
ExecStart=/usr/bin/sh /home/alarm/dns.sh

/etc/systemd/system/dns.timer

[Unit]
Description=dns

[Timer]
OnBootSec=10min
OnUnitActiveSec=10min

[Install]
WantedBy=timers.target

Start it with

systemctl start dns.timer

Related Posts