Testing nodeJS+ DynamoDB

You have an Express application with DynamoDB database and want to set up continuous integration and deployment? This article for you.

Setting up a testing environment

According to the twelve-factor app, env vars are granular controls, each fully orthogonal to other env vars and in my app environment variables is the main source of truth. At the moment of writing, I have three different places with env variables. First is the development environment(.env file), second is Bitbucket env variables, the third one is AWS Elastic(staging).

example of development env vars

Since AWS SDK has a global config object before any interaction with the database I should run AWS config code. It will specify credentials and point out that I want to use local DynamoDB rather than a remote one in a testing environment.

Before tests start I launch local dynamoDB database and create tables. When all tests are done I delete tables. In order to run these functions, I need to specify paths to them in package.json. According to Jest documentation, both functions should return a promise.

jest setting in a package.json
function that will run before all tests
function that will run after all tests


Sometimes you need to terminate tests and in such cases, globalTeardown will not execute. Better to delete tables first and after that create.



For continuous deployment, I will use Bitbucket pipelines. In pipelines, I need to download java and some packages required for AWS deployment.

the first version of pipelines

In order to optimize pipelines execution time, I decided to make Docker image with required packages.

Dockerfile for image

I was lazy to download and configure docker on a local machine. But there is a nice service on the Google cloud platform — Container Registry.

new pipelines

If you interested in making migrations in dynamoDB, take a look at this article.

Reach the next level of focus and productivity with increaser.org.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store