Member-only story
Testing DynamoDB offline with Serverless Framework

At some point in your serverless journey you’ll no doubt utilise DynamoDB. You’ll also probably want to be able to write integration tests against it. In this post we’ll go through the basics of getting an offline environment set up for testing, in a future post i’ll walk you through the couple of lines of code that needs to change if you want to utilise DynamoBBStreams (seperate post for SEO and maximum help for anyone debugging the issue).
Configuring serverless-dynamodb-local
We’ll begin by building on top of the serverless template I wrote about previously which can be found on github here. Whether you are using that template is irrelevant but I’ll assume you have a serverless project up and running already.
First thing we will pull serverless-dynamodb-local. This plugin will spin up a local instance of DyamoDB for us. Note: You’ll need to make sure you have JRE installed on your machine.
npm i -D serverless-dynamodb-local
Next we’ll add it to the plugins list (make sure it is above serverless-offline plugin)
plugins:
- serverless-dynamodb-local
- serverless-offline
We’ll also configure it to run during a test stage (jest sets the stage to test while running), allow it to…