How to run DynamoDB Locally and Offline [Complete Guide]

Written by Rafal Wilinski

Imagine you're traveling by plane to a different city, and the deadline for your DynamoDB-powered project is really tight. Obviously, during flight, there's no internet, but you just had one of these "Aha!" moments. You want to rush into the implementation, but there's one problem:

Since DynamoDB is fully managed NoSQL database, you cannot access it when you're offline. Bummer.

This didn't happened to me just once. Until recently, when I discovered I can run DynamoDB offline and locally on my computer, without AWS Cloud. In some scenarios, it makes developing and testing applications without accessing DynamoDB easier. In this guide, I'll show you how you can do that too. There are a few ways to do this; let's run through them below:

Different ways to setup DynamoDB locally

Using Docker

This is my favorite way because it does not require Java installed. In this setup, DynamoDB is running in an isolated container on the port of your choice. Another good thing about this solution is that it works the same across all the operating systems and can be easily added to your Docker Compose setup.

  1. Make sure you have Docker installed. If you don't have Docker yet, you can get it here.

  2. Open terminal and type:

And that's pretty much it.

Your DynamoDB local instance is now running on port 8000. If you want to connect to this container using SDK or CLI, don't forget to change the endpoint parameter in the configuration. Otherwise, you'll keep trying to connect to the AWS network.

Using Java

In this setup, we're running Java binary in our system without any containerization. It's a bit more complicated

  1. First, make sure you have Java Runtime Environment (JRE) version 6.x or newer already installed. It's required to run DynamoDB locally.

  2. Second, download DynamoDB

  3. Then, extract the archive and copy its contents to a location of your choice.

  4. Lastly, open terminal in the location where you've extracted files in step 3 and enter the following command:

DynamoDB is now running on port 8000. If you want to change it, use -port flag.

Similar to the Docker setup, you need to change the endpoint parameter in the configuration.

Running out of memory

If you're going to use DynamoDB really heavily, it's possible that the allocated amount of memory for your JVM might not be enough. In a case like that, use a combination of Xms and Xmx flags to adjust the amount of RAM. For example:

This will start your local DynamoDB instance with 256 MB of memory and allow the process to use up to 2048 MB of memory.

With Serverless Framework

Using DynamoDB with Serverless Framework is a pretty popular combination. DDB in a case like this one is perfect for running offline integration tests or just running local replica of the AWS environment for development purposes. Here's how:

  1. Run following command:
  1. Open serverless.yml file and add the following entry to the plugins section:
  1. Now, run the following command to let the plugin setup everything for us, including downloading DynamoDB Local:
  1. If you don't have DynamoDB tables defined in your serverless.yml file, do it now.

  2. Finally, start DynamoDB Local and migrate by running this command:

For more information, checkout the plugin docs.

Using LocalStack

LocalStack is a project aiming to mock most of the AWS resources locally. Once again, in my opinion, using Localstack is much easier with Docker. Running DynamoDB local with it look like this:

This will run a container exposing three ports:

  • 4572 running S3
  • 4569 running DynamoDB
  • 8080 running Localstack's status dashboard

Similar to the previous approaches, if we want to use our offline services, we need to set the endpoint parameter of SDK or CLI to http://localhost:4569. If you don't want to set the endpoint setting explicitly when using CLI with each command, alternatively, you can use awscli-local.

Querying and visualizing offline data

Dynobase UI with DynamoDB offline

Even though DynamoDB offline comes with an interactive shell that allows you to query and modify data inside the database using a web-based console, I found it a bit clunky. Fortunately, Dynobase works with DynamoDB local just like with the AWS managed one.

Dynobase is a Professional GUI Client for DynamoDB

Start your 7-day free trial today

Product Features

© 2020 Dynobase

Using DynamoDB Console frequently?
Try Dynobase to accelerate your DynamoDB workflow. Start your 7-day free trial today.