I’ve been using normal relational databases for far too many years, but as I’ve been exploring the Amazon Web Services (AWS), I came across their NoSQL offering ‘dynamodb’.

As the name suggests, AWS expects you to run their services in ‘the cloud’ but at the point I was getting ready to look at it, I was going to be stuck on a flight for a couple of hours – an ideal time to try things out, but not without internet access. Luckily AWS have provided a means of trying it out locally.

Heading to their site, you can download either a tar or zip package – it needs a JRE of version 6 or later. Extract the file and then the code can be run by the command:

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

from the folder containing the .jar file.

This as a result will start a local version of the database, contactable via port 8000 @ localhost.

Managing dynamodb the linux way

However, that’s a custom command to remember, and Linux gives us a standard way of starting and stopping services so I spent a bit of time to put together a systemd service to run the Java code.

The service assumes you’ve installed the Java package in /opt/deploy so if you install somewhere else, change any references to it below.

For a new service, we need to create a systemd configuration file – in this case, the file should be /lib/systemd/system/dynamodb-server.service which should be owned by root (look at the other files in /lib/systemd/system for exact permissions). The dynamodb-server.service file should contain the following code:

Once that file is in place, you’ll need to reload the systemd files with the command sudo systemctl daemon-reload. We can the stop and start the service using the systemctl commands below:

sudo systemctl start dynamodb-server

sudo systemctl start dynamodb-server

With the service running, and the aws cli installed, we can test it out by running a command such as

aws dynamodb –endpoint-url=http://localhost:8000 list-tables

Want to save time?

I’ve put together a script that will download the Java package, install it and the systemd commands.

If you want to look at it in detail, head over to https://github.com/simonhanmer/local_dynamodb, but for the short version, run the following commands

wget https://github.com/simonhanmer/local_dynamodb/raw/master/dynamodb_setup.sh

sudo bash ./dynamodb_setup.sh

Obviously, the normal warning about running code with sudo apply but the code basically

  • pulls down the AWS dynamodb package
  • extracts it to /opt/dynamodb, creating /opt/dynamodb/data to hold the datafiles
  • creates a systemd service, dynamodb-server to manage running dynamodb