Local Amazon DynamoDB - tools, dump/restore and testing

Setup

Download and extract dynamodb local to some folder.

Launch it (-sharedDb allows us to connect to the same database with other tools):

    $ java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

By default it will be running on the port 8000 and will create the db file in the same directory where it was launched.

Without the -sharedDB parameter the DB file name depends on connection parameters, the name is {awsaccess_key_id}{region_name}.db. So different clients can use different databases.

There is also an -inMemory parameter to keep data in memory:

    $ java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar - inMemory -sharedDb

How to load a test data and dump/restore the data

The easiest way is to create some script to generate the test data. This way it is possible to run DynamoDB local in memory and populate it with test data after launch. Another way is to dump real db data and restore it into local DB. Here are some related tools to help with this and similar tasks:

DynamoDb local web shell

DynamoDB local also has a web shell available via http://localhost:8000/shell. Make sure you launched the database with a -sharedDb flag.

Without the -sharedDb it will use {access_key}_us-west-2.db file. Access key can be set in shell settings, but the region name is hard-coded as us-west-2 (see source in chrome dev tools, /shell/jsrepl/sandbox.js file).

AWS Explorer

AWS Explorer is a toolkit for eclipse which contains the DynamoDb GUI.

Install it as described here.

To browse an application database start the DynamoDb local with the -sharedDb flag and select 'local' region in the AWS regions dropdown.

Without the -sharedDb Eclipse will use a file like AKXAX4X6XAFXIXNIXEXA_local.db.

Table prefixes

DynamoDB has a single namespace for all tables, so it is better to use table prefixes for different environments and/or different applications.

DynamoDB mocks and testing

While tools mentioned above are good to examine the data generated by your application the simplest way to verify your code is to build a set of unit tests.

DynamoDB Local is too slow for unit tests and it is better to use some other dynamo mock. In my current project I use a custom mock which is a simplified boto API implementation. Try to search for some native implementation of the dynamo API in your project language which will hold all the data in memory.

Also, a good idea is to make DB access configurable for tests so it will be easy to switch tests between mock / local db / real db.

DynamoDB Mocks: