From Prototype to Production in one weekend using Serverless

By Thomas Schoffelen

Thomas Schoffelen

Last year, the #LMF team built a prototype of MAAT, a smartwatch tool to help cognitively challenged children and adults adhere to a daily schedule, an idea from teacher-turned-entrepreneur Esther Goossens.

Image for post
Image for post

This month, we worked on turning that prototype into something that was production ready in order to release it to a wider audience. One of the main things that needed to happen for that was rebuilding the back-end API. This had previously been built on an internal PHP framework that is no longer maintained, and wouldn’t be suitable for further development.

We only had two days to build that new backend. As with most of our recent projects, we decided to go for AWS Lambda, DynamoDB and the Serverless framework. Here’s how we did it.

Modelling the table

I remember being so confused about single-table DynamoDB database design when I first learned about it, coming from a SQL-background, but am happy to see that with every database design we do, modelling goes faster and easier, and this one only took us about 30 minutes to think over and write out.

Since we already had a API specification, there was a clear list of database access patterns available. We reviewed them and made some small adjustments to the endpoints list based on learnings from building the prototype and ideas about upcoming functionality.

From there, we started modelling the table in a Google sheet. I always start with the same four fields: pk, sk, type, id

Base model:

Image for post
Image for post

After we’ve looked at access patterns and added attributes:

Image for post
Image for post

Project scaffolding

A few weeks ago, I built a little tool to scaffold Serverless Node.js projects. We added all of our API endpoints in there, downloaded the ZIP, inited a Git repo and set up CircleCI.

The scaffold comes with some unit test scaffolding as well. We didn’t manage to get up to 100% code coverage during our 2-day sprint, but we did write unit tests for the more complicated parts of the business logic in the API.

API Gateway v2

We also used the new HTTP APIs in API Gateway. That made it very simple to add JWT token authentication with just a few lines of config in our serverless.yml file.

We used Cognito user groups to regulate access, so that we can generate multiple users per account/organisation.

Amplify authentication

To speed up building authentication, we used AWS Amplify’s React UI for login and signup, which allowed us to have authentication in our web app implemented in less than an hour.