How to Create a NoSQL Table using Amazon DynamoDB

Jonathan Hernandez
Strategio
Published in
6 min readFeb 18, 2022

Databases made easy with Amazon!

Have you ever wanted to create a NoSQL database but it sounded like a complex task?

Today I will show you an easy-to-use database solution that Amazon AWS offers. It is called Amazon DynamoDB.

According to Amazon, DynamoDB is a fully managed NoSQL database that supports both document and key-value store models. It is a great fit for mobile, web gaming, ad tech, IoT, and many other applications.

A couple of things that I really liked about it are that creating tables is a very straightforward process, and the querying tools are simple to learn as well.

Enough about what I like… Lets get to the tutorial so you can start using Amazon DynamoDB too!

Prerequisites:

  • an Amazon AWS Account

Step 1: Create the NoSQL Table using DynamoDB

Login into your AWS Account and search for DynamoDB in the services bar.

Once you are on the DynamoDB Console page click on the Create Table button.

Clicking Create table will take you to the table configuration page. Here you can begin adding table details such as the Table Name, the Partition Key, and the Sort Key.

The Partition Key is a value that is used to identify and retrieve rows from your table. The Sort Key is optional, but it allows you to search or sort among items that share the same Partition Key. We will see these both in use later on in the tutorial.

For this tutorial, I will name my table NBA_Teams, set my partition, and sort keys to City and Name.

Table Name
Partition and Sort Key

For the Settings, Default settings are the fastest way to create your table. But for this example, we will choose Customize settings. This way we can make sure that Auto Scaling is on.

Auto Scaling augments resources when application demand increases or decreases. We will not need it for this small example, but I wanted you to know that it exists.

One of the benefits of using Auto Scaling is that it promotes high availability. For example, when the number of user requests grows, the provisioned capacity will scale up to accommodate the increased load.

Customize settings option
Auto Scaling ON

The rest of the settings can be left with their default values. Scroll to the bottom of the page and select Create table.

Create table button

Step 2: Input data into the table

Next, we will begin adding data to our newly created table!

Once you click Create table, you will be taken back to the DynamoDB console page. In the Tables section, you should see your table listed.

Click on your table’s name to navigate to the table’s page. Below you can see that we are on our table’s page. Our table is called “NBA_Teams”.

To start adding values to our table we will click the Actions dropdown menu and select Create Item.

Actions dropdown menu

In the Create Item Page. We are able to add value for both of our keys. For the example, below I added the value Chicago for the City — Partition Key and the value of Bulls for the Name — Sort key.

Once you add the values, click Create an item to add them to the table. Repeat this process as many times as you would like to add more items to your table.

Create Item Page

Step 3: How to query the table

DynamoDB offers a very convenient console that makes it super easy to query the table you created. To get there, navigate back to your table’s page and select Explore table items.

Explore table items button

Once you are on the Explore items page you should see all of the data that is in your table. You will also see a Scan and Query option as well. Within the Query option, you can begin building your search query to look for specific items in your table. For the example, below we will query the table using the words “Los Angeles” in the Partition key. As you can see that will return 2 results found in the table.

Partition Key query

In the previous example, we see that 2 results were returned because they share the same Partition Key.

If we would like to refine the results of the query, even more, we can add the Sort key to the query as well. In the example below, we add a Sort key to the query that returns a value only if it begins with the letter “C”.

additional sort key added to query

Step 4: How to delete items and delete the table

So far we have learned how to create a table, and how to query a table. Now we will learn how to delete table items, as well as how to delete a table.

Deleting table items in DynamoDB is a very straightforward process. From the Explore items page, you can select the item you would like to delete. In the example below we select the row containing “Orlando” and “Magic”. Once you select your row (or rows), you then click on the Actions Dropdown menu and select Delete items. This will delete the selected items from your table.

Items in the process of deletion.

To delete your table you will need to return to the Tables page. Once you are there, select the table you would like to delete and click the Delete button.

You will be prompted to confirm your deletion. Once you follow those prompts your table will be deleted!

Congrats! You now know how to use DynamoDB to CREATE, QUERY, and also DELETE tables.

If you made it this far GREAT JOB!

I think Amazon DynamoDB offers a quick and easy way to start working with Databases. If you are someone who is not too comfortable with using SQL yet, and perhaps that has held you back. I think this is a great way for you to start working with tables.

I hope this was a great learning experience for you. Let me know what you think in the comments below.

Follow me for more content as I dive deeper into the world of DevOps and Software Engineering.

--

--

Jonathan Hernandez
Strategio

Aspiring DevOps Engineer with 2+ years of IT Expertise and a passion to learn and teach new technologies.