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.
-sharedDB parameter the DB file name depends on connection parameters, the name is
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:
- 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 a
-sharedDb it will use
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 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.
-sharedDb Eclipse will use a file like
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.