Sunday, July 12, 2020

Building an Alexa Skill for Daily Covid-19 Stats Using Serverless

In my house, we always want to know how many new Covid-19 cases were recorded in our county over the last day. Obviously there are lots of places on the Internet where you can find this out. However, I'd rather just ask a digital assistant. So I built an Alexa skill and a system in AWS to back it up using serverless technology (Lambda and DynamoDB). Here I'll make a few notes on how I did it.

Here's the architecture:


I started by looking around for different data sources broken down by U.S. state and county that are being maintained around the web and settled on one being stored in a Github repo. So the first Lambda, update-stats, grabs the data once a day and processes it into DynamoDB.

One drawback to this particular data source is that it gives cumulative rather than daily counts. To derive the daily counts, I store the data over time. How to do this in DynamoDB and not preclude possible future extensions (like rollups over different dimensions) was the toughest decision I had to make on this project. Ultimately, I settled on a widening the table row (keyed by state:county) each day. Fingers crossed, but the virus should be long gone before I start to hit any row limits.

The second Lambda serves the Alexa skill. It simply loads the required row from DynamoDB and evaluates the two most recently added columns to calculate the daily change in positive cases.

The Lambdas are written in NodeJS, the AWS SDK, and alexa-message-builder and deployed and managed with Claudia.js. I wrote a few unit tests that I execute with Mocha; however, with Claudia, it's just as easy during development to upload and test most stuff inside the AWS console and CloudWatch logs.

I haven't made the skill public yet and am not sure if I will. Before that happens, there's a fair amount of productionization work left to do. Nonetheless, this was an interesting single-day project. Feel free to reach out if you have any questions.