You’ve recently set up a server at your home. You don’t quite feel comfortable hosting it in a service like AWS or you happened to have a machine lying around you want to try and get some use out of. You’ve gotten it up and running and forwarded incoming traffic from your router to be forwarded to the server. You set up the DNS and are happy with the results.
Several weeks go by and you’re at work. The weather is bad and you find out power was interrupted at your home. You are worried about the server (You didn’t use a surge protector or a UPS, did you?) and decide to try and connect. As you fear you can’t you go about your work and head home at the end of the day. The weather is clear and you arrive home to find the power is on. You try to connect to your server and everything is fine. You work into the evening and go to bed.
The next day at work you are trying to connect to your server again and find you can’t. You try everything but nothing works. You get home and find you can connect fine. You decide to check the external IP address has changed. You call your ISP and find out that they issue dynamic addresses to residential customers and either won’t give you a static one or are going to charge you far too much for one.
Solution
After some research you develop a plan to use AWS API Gateway and AWS Lamda. You plan on having a single API endpoint with two modes, get and set. The get method will simply return the IP address of whoever called the API. An example of calling the endpoint in the get mode is as follows:
The return value for the call will be the following:
The client can then use this information to calculate a secure SHA256 hash of the information it needs to pass to the API in the set mode. This hash will consist of IP_AddressHost_NameShared_Secret. If the client wants to update the IP address for host1.dyn.example.com to 192.168.0.1 with the shared secret of P@ssw0rd then it would pass SHA256(192.168.0.1host1.dyn.example.comP@ssw0rd) in the set as show below:
If the hostname does not need to be updated the following will be the return value:
If the hostname is updated then the following will be the return value:
You setup the API inside of AWS and configure it to use Lamda as the backend. You create a single Lamda function to use and after some trial and error have the following result:
An example of the configuration file stored in S3 is as follows:
An example of a bash-based client which can be set up as a cron job is as follows: