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).
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.
Update
Sometimes you need to terminate tests and in such cases, globalTeardown will not execute. Better to delete tables first and after that create.
https://gist.github.com/RodionChachura/6f1f8e5912863b6bc7ddb3abfd94ba61
CI/CD
For continuous deployment, I will use Bitbucket pipelines. In pipelines, I need to download java and some packages required for AWS deployment.
In order to optimize pipelines execution time, I decided to make Docker image with required packages.
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.
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.
