All you need to know about the Amazon DynamoDB

All you need to know about the Amazon DynamoDB

Serverless Password Manager using AWS KMS and Amazon DynamoDB Part-2

By Muhammad Abutahir

This blog is independent of the previous blog, if you are looking for dynamoDB information only, you can still read through it. For Part 1, please check out this link!

Alright, In the previous blog I gave an introduction on the encryption, the AWS KMS, and the dynamoDB encryption client library. In this blog, we will learn about Amazon DynamoDB, its use-cases, how to create a table, etc.

What is DynamoDB?

Amazon DynamoDB is a completely managed NoSQL database service, which means unlike any other relational databases where the data is stored in columns and rows, that is tables, in a NoSQL database, the data is stored in the form of a record or a document, which you can imagine like a JSON Object, where each record consists of key-value pairs.


Why Amazon DynamoDB?

Handling loads of data has to be one of the key factors of any database and another is scaling accordingly, and here, the Amazon DynamoDB stands out, it can handle TBs of data without any throttling issue and provides very low latency. To get a picture of this in your mind, during the last Prime Day sales in June 2021, Amazon DynamoDB handled about 89.2 million requests per second! that’s huge! isn’t it? Imagine the scale rate of this DB, over the course of 66-hour Prime Day, the sources made trillions of API calls and the dynamoDB offered high availability even in such a hot case.

Querying the data in DynamoDB is very simple if the database is configured properly according to how the application demands. It provides multiple indexes which you can use to query the data, and most importantly for our use case, DynamoDB provides encryption at rest, which is very important to store the credentials we want to.

The next thing is it supports AWS Lambda, which provides auto-scaling and ephemeral compute and DynamoDB can be accessed via HTTP APIs which is a perfect combination for building serverless applications, which we are going to build soon.

DynamoDB also scales up and down according to the application’s needs.

Let us know some important concepts.

Tables: Imagine it just like a normal table in any of the databases, the Amazon dynamoDB table is a collection of data or items.

Items: An item can be imagined like a JSON object, which can have multiple attributes, which is already discussed above. You can store any number of items in a table. Every item must be associated with a primary key, this is one of the key points of contact to fetch the data and this makes an item unique.

Attributes: An Item can have any number of attributes, an attribute can be imagined just like a key in a JSON Object.

Primary Keys: In DynamoDB a primary key can be a combination of the Partition Key and Sort Key, if that scares you, these are just unique identifier attributes. The partition key must be mandatorily provided at the time of table creation making it the simple primary key, but the sort key is optional and can be used based on the needs. A partition key can be anything like a number or a string, but it should be unique, just like an ID. A partition key and sort key combined together is referred to as a composite key.

Secondary Indexes: DynamoDB provides you with indexes that you can use to query your data by using attributes other than primary keys, for example, if a table has a primary key named employeeId we can have department as an index to fetch all the employees of a particular department.

DynamoDB provides two types of secondary indexes:

  • Global secondary index: These are any indexes having a partition key and sort key other than the table’s primary key.

  • Local secondary index: These are any indexes having the partition key the same as the table and a different attribute as the sort key.

You can refer to these docs for deeper information. I have given information that is needed for our project, and for most of the starter projects, this should be enough.

The Amazon DynamoDB Pricing

The DynamoDB charges based on read requests, write requests, and on any additional features that you enable, also on storing your data. It provides two capacity modes.

  • On-Demand

  • Provisioned

On-demand as the name suggests, it costs as per the read and write requests that your application demands, you don’t need to configure how many of these IO requests your application would need, it’s pretty automatic.

It charges 1.25 dollars per million write request units, one write request unit is almost 1 KB, and 0.25 dollars per million read request units, one read is up to 4 KB. More charges can be applied based on the usage of extra features. The first 25 Gb of data stored is free per month and 0.25 dollars per GB a month after that.

In Provisioned mode, on the other hand, you need to specify how many of these IO requests you expect in your application.

Here DynamoDB costs in WCU (Write Capacity Unit) per write, and the WCU in terms of money costs $0.00065 per WCU, and this is hourly. Similarly, for read requests, it costs one RCU(Read Capacity Unit) per read, which is about 4 KB, and in terms of money, it costs $0.00013 per RCU.

For more information about the pricing of extra features, you can refer to these docs. I have given you pricing considering the DynamoDB Standard table class, which means the class which is frequently accessed.

Creating a DynamoDB table

The creation of a table in dynamoDb is straightforward, this can be created by the console or by the cloud formation template, for the sake of this example, let’s create a table from the console. To create the table follow the below steps.

We will design the actual table needed for our password manager in the next blog. The primary focus of this blog is to completely give you an understanding of DynamoDB.

Search for DynamoDB in the AWS dashboard and click on DynamoDB.

Click on Create table

Give the table name and specify the Primary key and its datatype according to your needs, we now know that the primary key in dynamodb is a combination of Partition Key and Sort Key, however, the Sort key is optional as I already mentioned, but you must specify the partition key mandatorily and click on create.

When you select the table after the creation, you will get a screen like this, I named my partition key as partition-key, you can specify any name.


Firstly thank you for spending your valuable time on this blog, I really appreciate it.

In this blog we learnt about DynamoDB, we learnt why it should be used and how fast it is, in the next blog we will take a deep dive into my story of data modeling with dynamoDB and how I came up with a final model, we will learn what is a single table design and why it is important. We will also learn about creating and deploying the DynamoD table with the serverless framework.

Thanks for reading and have a nice day!



Aws Serverless

Cloud Computing

Cloud Services