easy dynamic dns built on AWS
Lambda, DynamoDB, Route53
Prereq: aws profile configured for sso login. if not yet done, follow this guide.
create a .env
file in the project root directory with the following content:
AWS_PROFILE=YOUR_AWS_PROFILE_NAME_CONFIGURED_IN_YOUR_AWS_CONFIG
AWS_REGION=THE_REGION_YOU_WANT_TO_DEPLOY_TO
AWS_HOSTED_ZONE_IDS=COMMA_SEPARATED_LIST_OF_THE_IDS_OF_YOUR_HOSTED_ZONE_IDS
- install all deps
npm ci
- set env and login
source set_env
aws sso login
- build it
npm run build
- deploy
npm run deploy
- create entry in DynamoDB in the following format:
- make sure the used zone id was provided to the env key when deploying, otherwise add it and deploy again
- it is up to you how long the ttl should be, depending on how often you want to call the api
- generate a secret key and use it in the request to update the record
{
"hostname": { "S": "my-host-name.ch" },
"zoneId": { "S": "your-zone-for-your-domain" },
"recordTtl": { "N": "172800" },
"secret": { "S": "a-very-secret-key" }
}
- after deploying you can execute the following command to get the api endpoint.
the command writes theoutputs.json
file which contains the api endpoint variable
./get-stack-outputs
- on the given endpoint you can now update the ip address of the record by sending a post request
- first get your public ip (e.g. by calling the api (see
apiFnUrl
in outputs.json) - store the current timestamp (seconds since epoch) in a variable
- then calculate the hash (sha256 hex) of
ipAddress + hostname + tiemstamp + secret
(joined without any special characters) - finally send the following json to the endpoint
- first get your public ip (e.g. by calling the api (see
{
"ddns_hostname": "my-host-name.ch",
"validation_hash": "the-calculated-hash",
"timestamp": 1736598400
}
you can use the provided update-dns-record script to automate this process
just set the env variablesSECRET
,HOSTNAME
andAPI_URL
and run the script
you can also use the Dockerfile to create an image and run it as a container