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.
Getting started
Create a new project directory to work within.
Summary
This post guides users through setting up DynamoDB for local development, including downloading and installing DynamoDB, starting the database, and using the AWS CLI to interact with tables.
Abstract
In this post, the author explains how to set up DynamoDB for local development and use the provided UI to explore data. The process involves creating a new project directory, downloading DynamoDB from the AWS documentation page, and unzipping the folder into the project directory. The author then provides instructions for starting the DB by running a specific command and adding it as a script in the package.json file. The post also covers using the AWS CLI to interact with tables and introduces NoSQL Workbench, an app provided by AWS that can operate as a GUI for users to interact with their data.
Opinions
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_lib and 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 package.json file:
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!
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.
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:
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 GetItem on 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:
As an added bonus, if you select Generate code, NoSQL Workbench will even generate some code in Python, JavaScript and Java for you to use or take inspiration from.
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.
Image credit: Lars Kienle
Originally posted on my blog.
Elye - A One Eye DeveloperIs Flutter Still Fulfilling its Purpose at Google?
Dario RadečićThe one billion row challenge is exploding in popularity. How well does Python stack up?
Akhilesh MishraUsing docker init to write Dockerfile and docker-compose configs
huizhou92Analyzing the Potential Impact of Google’s Discontinuation of Support for Go Language and Possible Future Scenarios
Alistair GrewEntering the graveyard of good software that is IBM…