Working Locally with DynamoDB In 60 Seconds

DynamoDB is a NoSQL type of database. It is very important to learn the difference before migrating an existing system or choosing DynamoDB for your new project. This article assumes you have that foundation and seeks to provide a quick overview of how to get DynamoDB running on your local machine so that you can prototype or test or just explore things locally.

Getting Started

In order to work with DynamoDB, you will need to have the AWS CLI installed on your machine. You should also already have your credentials configured. Once you've confirmed that you have the AWS CLI installed and your credentials configured, then you're ready for the first step.

Step One: Download DynamoDB

Without trying to oversell it, there are a few ways to get and use DynamoDB locally. Docker is certainly an option. I like the Docker option for all the standard Docker reasons, but this article is going to focus on downloading the .jar file because that will provide a walk through that doesn't beg for Docker explanations that would belong in a Docker article.
For your convenience, here is the link to the download page on AWS. Select a geographically convenient download, and when it finishes unzip the contents to an appropriate location on your file system. You should then navigate into that folder at the command line.
Because we downloaded the .jar file, the next step is to run DynamoDB.
java -Djava.library.path-./DynamoDBLocal_lib -jar DynamoDBLocal.jar -SharedDb

Now, DynamoDB should be up and running on port 8000. In order to test that, we can list the current tables in your local DynamoDB with the following command from a new command line:
aws dynamodb list-tables --endpoint-url http://localhost:8000.
This should return an empty list because you have not yet created a table.

With a relational database, you would usually have to know a little more about the kinds of data you would be storing; however, with DynamoDB there are three pieces of information needed to get a table created. You need a name, a primary key, and the throughput, or Read Capacity Units and Write Capacity Units.


if you fail to be certain this is local to your machine, you could end up costing yourself potentially a lot of money. Keep your RCU and WCU values low for now just in case.

Let's create a table. At the command line, type:
aws dynamodb create-table \
--table-name SomeName \
--attribute-definitions \
AttributeName=SomeName,AttributeType=S \
AttributeName=OtherName,AttributeType=S \
--key-schema \
AttributeName=SomeName,KeyType=HASH \
AttributeName=OtherName,KeyType=RANGE \
--provisioned-throughput \
ReadCapacityUnits=1,WriteCapacityUnits=1 \
--endpoint-url http://localhost:8000

Once you have created this table, you can check the create with the list-tables command again. And never forget --endpoint-url http://localhost:8000