Awhile back I wrote an article about how I have been using several AWS services (EC2, RDS, SQS, etc.) to run a small hockey pool website. In that article, I mentioned that one of my biggest goals was to move away from EC2-based Cron to Lambda and to build a more “loosely coupled” application.
Since a hockey pool website without stats would be pointless, I figured it was a good place to start. In this post, I’ll talk about how I moved from my original Cron-based setup to Lambda.
At this year’s Re: Invent conference the one keynote announcement that stood you for me, and based on the applause, quite a few other people was that you could now schedule Lambda jobs. Before this, Lambda functions could only be invoked by events with the AWS platform.
Honestly, the most difficult part of this process was converting the original script from Boto2 to Boto3. Most of the calls I was using no longer existed so I needed to do a fair amount of reading in the Boto documentation to understand which changes I need to make.
Once I got over that hurdle, the transition was seamless.
First, I created a new Lambda function, skipping the canned options AWS supplies.
It’s important to note here, that I created a new custom role for the hockey pool, which allows the function access to specific S3 buckets.
I started simply by just posting my Python code inline in the configuration window.
Finally, I scheduled the job to run once a day. When it runs it downloads the stats (daily and total) files and stores them in their respective S3 buckets
Total cost to run this Lambda function? 30 scheduled events (once a day), 128 MB of memory = $0
Like what you read? Why not subscribe to the weekly Orbit newsletter and get content before everyone else?