Hi all, in this blogpost I will give a brief overview of how I used AWS to remind me to take out the trash.
It’s a familiar scene: as you’re waking up or making your morning coffee, you hear the garbage truck roaring away outside when you suddenly realize your garbage bags are still rotting away in the garage. Do you run after the truck like a lunatic, even though it’s too late (of course I’ve never done this, but I’ve heard it’s a thing)? Or do you just let it go and let the garbage fester even longer? Either way, it’s a frustrating start to the day.
Luckily for me I live in the modern and very civilised province of Limburg of Belgium where the local government has made a website available with a downloadable calendar showing all dates the garbage truck comes along: so handy! They even provide the calendar in a number of digital formats, including iCal. I could just import this into my phone and set an alert on it, but where’s the fun in that? After some fiddling around or “reverse engineering” as they call it, I found out that the data for the calendar files was provided by an undocumented but publicly available API.
Being the sucker for coding up and fooling around with APIs that I am (and given my state of utter boredom while under full lockdown in Belgium) I decided to code up a project based on this API that would send me an SMS notification the evening before garbage collection. Because that’s my idea of fun. And that way I would be reminded to take out the trash on time and keep my garage clean.
Want to know this neat trick to save you from rubbish resentment? Read on!
So for this project I partly used the AWS SAM framework and set up a CodePipeline to deploy my code changes instantly on AWS (stay tuned for a future blogpost on this).
First let’s code up the AWS SAM template file containing the necessary resources for this project.
The resources I used are:
- Type: AWS::Events::Rule
A Cloudwatch event rule to invoke a lambda each evening around 8.
- Type: AWS::Lambda::Permission
To give the Cloudwatch event rule permissions to invoke the lambda.
- Type: AWS::Logs::LogGroup
A log group for the lambda logs.
- Type: AWS::Serverless::Function
The lambda that will run the show.
- Type: AWS::IAM::Role
An IAM role for the lambda to have the necessary rights like accessing SNS for the SMS notification.
Next we code up the lambda that will call the API and send us an SMS.
The API provides event data for each month by just requesting the year and month in the url path like this ‘/2020-03’. So we can easily get the data for the current month and loop through its events, checking whether any are occurring the next morning. If so we receive an SMS notifying us (note that you can provide the number of your girlfriend here, but it’s not recommended as I have found out it isn’t that effective).
And that’s all folks!
I’m aware that this trick is no rocket science, and that this isn’t even a full guide to get to the same result (leave a comment if you want some more details), but I thought it would be fun to share how I resolved one of life’s little problems using AWS.
As I’m moving toward two years of professional experience using the platform, I’m still amazed at how easily you can code some services together and create a working, scalable and highly available project in a matter of minutes or hours.
Hope you liked my trashy tale – keep your garages clean and your heads in the cloud!