Amazon DynamoDB: local setup, dump/restore and other tools
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 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 {aws_access_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 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 the local DB. Here are some related tools to help with this and similar tasks:
- dynamodump - Simple backup and restore for Amazon DynamoDB using boto
dynamodb_utils- A toolchain for Amazon's DynamoDB to make common operations (backup, restore backups) easier- DynamoDBtoCSV - Dump DynamoDB data into a CSV file and related blog post
- dynamo-archive - Archive and Restore DynamoDB Tables
- AWS DynamoDB to MongoDB Conversion
DynamoDB Local web shell
DynamoDB Local also has a web shell available via
http://localhost:8000/shell. Make sure you launched the database with the
-sharedDb flag.
Without the -sharedDb flag, it will use the {access_key}_us-west-2.db file.
The access key can be set in shell settings, but the region name is
hard-coded as us-west-2 (see the source in Chrome DevTools,
/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 DynamoDB Local with the
-sharedDb flag and select the 'local' region in the AWS regions dropdown.
Without the -sharedDb flag, 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 the 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, it's a good idea to make DB access configurable for tests, so it will be easy to switch tests between mock / local db / real db.
DynamoDB Mocks: