edit: As of September 2022, toll-free numbers now require registration, and is required for this to work. To update, follow these steps.
Function to periodically check that my websites are up, and sends me a text-message if not.
I have a couple small websites (eg havewemadeagiyet.com and tomhenighan.com). Recently one of them went down for a silly reason and I didn't realize for a while. If that happens again, this should send me a text message so I can fix it.
This is meant to be simple, and doesnt check latency or global availability.
I'm sure there are much better off-the-shelf tools I could have used here instead. But I deicded to use this as an opportunity to play with terraform.
This uses a lambda function which makes get-requests to my websites and asserts that the returncode is 200. If not, it uses SNS to notify me via text. The lambda function is triggered every 24 hours using eventbridge. Most of the cloud infra is managed using terraform, though I had to set up a few SNS things via the aws console.
You will need:
a. An aws account
b. Terraform installed with admin priviliges on your aws account (including the ability to create iam roles and policies).
To be able to text my US number, I needed to purchase an origination phone number. I went here on the pinpoint console and purchased a transactional, toll-free, sms-only phone number. This annoyingly costs $2/month. You will also need to regieser this number by following these steps.
Because of the above cost, I also tried using aws SES instead, but all the emails I sent to myself went straight to spam (unsurprising). This was also a sub-optimal solution for me because I rarely check email.
In the aws console, navigate to SNS->"SMS and voice" in the SNS here and add your number to the destination phone numbers. Follow the steps to verify it.
Note I'm keeping my account in the "SMS Sandbox", as I have no need for sending notifications to anyone but myself.
Find the following list of urls and replace with the urls you'd like to check:
urls_to_check = [
"https://tomhenighan.com",
"https://www.tomhenighan.com",
...
./update_zip.sh
This will install the required python packages (listed in requirements.txt) to a "packages" folder and zip that together with ./lambda_script.py. We will upload this zip to the lambda function.
terraform init
(must be run inside this directory)
terraform apply -var 'PHONE_NUMBER=12223334444'
(also must be run inside this directory)
Replace 12223334444
with your phone number, including country code (ie for US numbers should start with a 1
, then area code, etc).
Terraform will display the resources to be created and ask for confirmation.