In this post, we will set up DynamoDB for local development and learn how to use the provided UI to explore the data we work with.
Create a new project directory to work within.
Head to the AWS documentation page and download a version of DynamoDB into the project directory.
I will download the Oregon zip file.
Ensure to unzip the folder into the project directory. Within that folder, I am going to move the
DynamoDBLocal.jar file up to the project directory root (you can remove what is left of the folder after if you would like).
Now we can start the DB by running
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb.
I am going to add that line as a script in the
First look after running DynamoDB
Now that we have our script in
package.json, we can run
npm run start:db to get up and running:
Once it is running, we can use the AWS CLI to begin interacting with our table locally.
If we run
aws dynamodb list-tables --endpoint-url http://localhost:8000 we will get the following:
Although we currently have no tables, we have success with setting up!
Setting up NoSQL Workbench
AWS also provides an app NoSQL Workbench that can operate as a GUI for us to use.
To try it, head to the NoSQL Workbench installation page and download the application for your system.
Adding a Table via the NoSQL Workbench
Once you open the workbench, if you head to Amazon DynamoDB on the left-hand side panel, you will have some sample models that you can hover over and import.
Now if we run
aws dynamodb list-tables --endpoint-url http://localhost:8000 we will see the data has been imported to our local database:
Running queries with the NoSQL Workbench
In order to run queries against the local, select the Operation builder on the left-hand side panel. Once there, select Add connection, choose the DynamoDB local tab and ensure that the details there are correct to your localhost port and add the connection.
Now we can run a simple
Amazon DynamoDB for the Forum table.
First, head back to the Amazon DynamoDB tab, hover over the AWS Discussion Forum Data Model and open it. This will take you to the Data modeler. From here, select Visualize data model to open the Visualizer. Finally, select Commit to Amazon DynamoDB and from the Saved connections you can now select you localhost instance to commit the tables.
Now we can open up the connection in the operation builder and select the Forum table.
Exploring the data in the table gives us an idea of some basic queries we can make.
If you select Expand operation, select GetItem from the data plane operations dropdown and Forum from the table dropdown, we can then pop a value such as Amazon MQ into the required Partition key value.
Selecting it will return the values for that particular item:
From here, we can plan out our tables and run CRUD operations to test these from within the NoSQL Workbench and our local DynamoDB instance!
To recap today’s short post, we set up a simple way to run DynamoDB locally from a simple project and then explored the NoSQL Workbench and did a basic GetItem request to show how we can connect up our local DynamoDB.
This first post on the topic is short and simple, but you can take parts of it and elaborate ie set global commands to run DynamoDB from anywhere.
Resources and Further Reading
Image credit: Lars Kienle
Originally posted on my blog.