This article will discuss Amazon DynamoDB, a NoSQL database that can provide predictable performance and uniform scalability. DynamoDB is an Amazon proprietary NoSQL database.

We will discuss the following:

  • Introductory concepts
  • Creating a DynamoDB table
  • Loading data in a DynamoDB table
  • Querying data from a DynamoDB table
  • Deleting a DynamoDB table

Introductory Concepts

A NoSQL database is different from a relational database (MySQL for instance) in that the data can be modelled in ways other than tabular relations. NoSQL databases are utilized more and more in real-time web and big data applications.

In relational databases, the table has a well known defined schema. The table has to have the list of the columns and their data types. Any record stored must have the same set of columns. In comparison, the table in DynamoDB is schema-less, except the primary key and each item in the table can have any number of attributes. An attribute is a name-value pair.

VMware Training – Resources (Intense)

In Amazon DynamoDB, the data is organized in tables, items and attributes. A database is a collection of tables, which subsequently are a collection of items, with each item identified by attributes.

When you create a DynamoDB table, you must specify the primary key of the table. There are two types of primary keys:

  • Hash type primary key: Has one attribute, the hash attribute. An unordered hash index is built for the primary key attribute.
  • Hash and range type primary key: Has two attributes; the first one is the hash attribute and the second one is the range attribute. Same unordered hash index is built for the hash attribute and an ordered range index for the range primary key.

There are two data types that can be used with DynamoDB:

  • Scalar data types: number, string, binary
  • Multi-valued types: string set, number set, binary set

The data in DynamoDB is stored in solid state disks and replicated across multiple AZ in one Region for high availability and high redundancy.

You can perform:

  • Table operations: Create, update and delete.
  • Item operations: Add, update and delete items from tables.
  • Query and scan: Query the table using the hash attribute and optionally the range filter. The scan operation examines every item from the table.

DynamoDB Table Operations

So let’s get started and create a DynamoDB table and use it.

From the AWS console, under “Database” section, choose “DynamoDB”:

Click on “Create Table” to start the process of creating a table. Then in the next window, fill the form as you can see in the screenshot:

Fill in the table name, the hash attribute and range attribute name and click on “Continue” to get to the next step of table creation:

Leave everything as it is and click on “Continue”:

Click on “Continue” to get to the next step.

You can designate an email address to which the alarms will be sent in case you cross over the threshold.

At the next step, you will get an overview of what you created:

After you click on “Create”, the table will be shown in the table list. It will take some time to complete (the state should be “ACTIVE”). Until then, you will see the status “CREATING”:

Once the table is created, it’s time to fill in the data:

Once you click on “Put Item”, you will be notified that the data was added:

If you go back and click on “Explore Table”, you will see the data added:

Let’s add more data like this so we can perform some operations on it. I added another four similar records and now the table looks like this:

If you want to edit one item from the table, from the table list, click on “Explore Table” and then double click on the item you want to edit:

Click on “Edit Item” and modify the item accordingly. Then click on “Update”:

Let’s retrieve data from the table by using the query function.

From the table list, select the table and then click on “Explore Table”. From there select the “Query” function and you should get the following screen:

Let’s find out what car, top speed and how many wins the user 1003 have. You will need to fill out the query fields like this:

You could narrow down the search by using the “Range Key” as well. You can restrict the search criteria for usernames that start with a specific letter for instance, like below:

You can delete a table by selecting the table and then clicking on “Delete Table”:

Once you click on “Delete”, the table will be in “DELETING” state and will shortly no longer appear in the table list:

And that’s it for the basics of AmazonDB. By reaching this part of the article, you should be familiar with what DynamoDB is and how to create a table, upload the data into the table, edit the data, query the data from the table and delete the table.

This is a glimpse of what you could achieve using Amazon DynamoDB.

Actually, DynamoDB on its own doesn’t do too much. So what if you have a DynamoDB table? You will still need a frontend to access the data from the table. Usually these are web applications using the AWS SDK to make the API calls to the Amazon DynamoDB. For this you will need to know programming languages like Python or Java to build these web applications.

However, the purpose of the article is to show you how you can manipulate the DynamoDB table. If you know what it can do, then you can automate tasks and build powerful applications.

References