Earlier this year, I found myself in need of a little monitor. To be more specific, there's this artistic fellow who puts "limited number/run" stuff up for sale on his website at seemingly random times. And I've missed the opportunity to purchase some of his stuff because I didn't realize it was up for sale (bummer!). So I wanted something automated to check his website frequently and alert me to any changes. This situation looked like a great excuse for me to try out AWS' Lambda offering.
Enter the Lambda
Introduced in 2014, Wikipedia describes AWS Lambda as "an event-driven, serverless computing platform" which is a compute service "that runs code in response to events and automatically manages the compute resources required by that code". Lambda is designed so that you don't have to provision it yourself (Amazon automagically handles where your code runs), billing you only for the time your Lambda function (i.e. code) takes to run. Since its inception, Lambda has grown to support a number of different event triggers and interacts with many different AWS services.
In my case, I wanted something trigger by a timer that would go check the website and see if new items for sale had been listed. And Amazon had a tutorial which got me 90% of the way there right out of the gate. Perfect!
The Tutorial Flow
The lambda-canary "blueprints" AWS offers are Python code snippets which will go check a website and throw an error if there was a problem reaching or loading the website. Using a periodic timer setup in AWS CloudWatch, the Python code is executed at whatever frequency you've selected. If an error occurred reaching or loading the target website, the code will raise an exception. This exception gets caught by CloudWatch monitoring, who will increment the "error" metric count, triggering an alarm you've set up for when errors >= 1. And this alarm triggers the SNS alert you setup, so you get an email or text or however the SNS is configured to message you. Not too shabby! I tweaked the Python code a bit in my case to look for specific strings of text in the loaded webpage ("coming soon", "out of stock", etc.), and I was good to go!
The Cost
So having a little Lambda function to check a website every minute of every hour of every of every day of every week (etc.) turns out to be REALLY cheap. Here's how billing during my first month of running looked:
To be fair, it did end up costing $0.02 for my first month of March (Amazon's mid-month forecast was off by a penny, dang! :P ), but has been usually $0.01 per month since.
Wrap it Up Already...
My experiment has been super cheap and really fun (and allowed me catch those artist's items I had been missing out on!). I have some improvements I'd like to make, or course, but it's mind boggling to me just how inexpensive it is to run a task like this. While Lambda won't lend itself well to some types of tasks, it does appear to be a very nice option for those it does!