Hi all, in this blogpost I will give a brief overview of how I used AWS to notify me when it’s time to take out the trash.
As we all know it’s sometimes hard to remember to put out the trash in time, resulting in a frustrating morning when you hear the truck outside taking away the garbage while yours is still rotting away in the garage. (happens more often than yours truly would like to admit)
Luckily for me I live in the modern and well civilised province Limburg in Belgium where the local government has made a website available on which they provide you with a downloadable calendar with all dates the garbage truck comes along. They provide it in a number of digital formats including ical and it would be possible for me to just import this in my phone and set some alerts on it but wheres the fun in that right. After some fiddling around or ‘reverse engineering’ as the professional term sounds, I soon found out that the data for the calendar files was provided by an undocumented but publicly available api.
Being the ‘code up and fool around with api’s’ addict I am and as we are at the moment of writing in full lockdown in Belgium due to the COVID-19 pandemic I decided to code up a project based on this api that will send me an sms notification the evening before garbage collection, reminding me to take out the trash in time and keeping my garage clean.
So let’s get started shall we!
For this project I partly used the AWS SAM framework and set up a CodePipeline to deploy my code changes instantly on AWS. (maybe 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 trough it’s events checking if any occur on the next morning. If so we will 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’s not that effective.
And that’s all folks!
I’m aware that the above project is no rocket science and not even a full guide to come to the same result (leave a comment if you want some more details), though I thought it would be fun to share how I resolved a little issue I’m dealing with using AWS.
As I’m moving towards 2 years of professional experience using the platform I’m still amazed at how easy you can code some services together and result in a working, scalable and high available project in a matter of minutes to hours.
Keep your garages clean and your heads in the cloud!