Tech

Get to know AWS DynamoDB


Introduction

Following the growth of startups and big tech giants, data expansion is something that shouldn’t come as a surprise. Whether we like it or not, from an infrastructure perspective, we are going to face a very specific problem => How do we pick an appropriate solution for seamless data scaling, but also make it fast, reliable and secure? 

When asking such questions, some of the responses tend to be  

  • Hey, I’ve used mongoDB for 5 years straight and it rocks!
  • Awesome experience with Cassandra, you should check it out
  • Man, have you seen how many good things you can do with ElasticSearch?

But then you ask them :

  • So, how secure is it?
  • How do I deploy this thing?
  • Do I have regular backups right off the bat?
  • How do you propose I scale it?

To answer those questions, we will talk about one of the most popular NoSQL databases that offer a wide majority of things natively and is serverless! How cool is that? Let’s look into AWS’s DynamoDB 

AWS DynamoDb Featured Image

What is DynamoDB?

DynamoDB is Amazon’s NoSQL database that is fully driven by AWS’s ecosystem. It consists of tables that contain key-value relationship items and are blazingly fast to retrieve. You can create as many tables as you like and span them across multiple regions.

So, the answer to the questions above :

  • Security? Dynamo is as secure as logging with Apache’s Log4J 🙂 Jokes aside, it really is secure. AWS provides immediate strong cloud security. Every data that goes out and comes into DynamoDB is encrypted. They are also tested and validated by third-party auditors. More on this topic here.
  • Deployment? You don’t have to worry about it here. Everything is handled on the cloud by AWS
  • Database backups? Of course! It’s just a checkmark away in Settings !
  • Many data? Scaling is the biggest strength of DynamoDb

Creating a new table

To create our first table we should sign in to our AWS account. After that, in the search bar, type DynamoDB, to locate this service.

AWS Search Console

When clicking on DynamoDB, the following screen loads up

AWS DynamoDb Homepage

You should click on “Create table” to start creating in DynamoDB. Once the form is presented, it should look like this

Creating DynamoDb Table - Table details

Table Details

You can enter any name for your table. We will name our blog. Be careful when choosing your private and sort keys. Those are irreplaceable, once a table is created. If you are however in need to change the key schema you will need to migrate your table to a newly created table that contains your new key schema.

The partition key is is a part of a primary key and it’s mandatory. This is usually an id field and you get to pick its type. From our experience, leaving it as String was the most suiting for our purposes. One important thing to remember is that DynamoDB doesn’t have an AUTO-INCREMENT feature or any random id generation whatsoever for that field. For each new item you create in the table, you have to handle id generation.

The sort key is also a primary key part, but it’s only optional. It can really speed up your queries, if you are planning on sorting items by date for example, or returning items in a date range, making it more cost-effective.

We will pick the partition key to be id and will not pick a sort key.

Moving on to the further settings

Creating DynamoDb Table - Default settings

We will leave this setting as is. Default settings are all right for most use cases. If you know how many read capacity units ( RCU ) and write capacity units ( WCU ) you might need, you can select “Customize settings” as you will be able to modify them. Changing these values, as well as adding secondary indexes, can be done even after table creation.

On the bottom of the page, there is a button saying “Create table”. Clicking on it will start table provisioning which usually takes less than a minute. We now have our table operating: 

Create DynamoDb table - Blog

Creating items

Let’s click on the blog. It should open up a table interface for us

Table Interface

Let’s go to Actions => Create Item and paste in the following JSON. We are going to create an item that has 3 attributes:

  • id, which is a mandatory part of the primary key,
  • title and
  • an array of tags

“S” in JSON that Dynamo accepts stands for data of type String. It could also be “N”, for Number “L” for List ( Array ), etc. More on supported data types you can find here  

{
 "id": {
  "S": "5178c096"
 },
 "title": {
  "S": "Get to Know AWS DynamoDb"
 },
 "tags": {
  "L": [
   {
    "S": "aws"
   },
   {
    "S": "database"
   },
   {
    "S": "nosql"
   }
  ]
 }
}

It’s going to be shown like this

DynamoDb JSON Item Creation

Finish item creation by clicking on the orange “Create item” button.

To examine the created item after creation, click on “Explore table items” and you can see your first item is saved

Explore New Item

Congratulations! You’ve reached the end of this post. We hope you learned new things along the way.
One caveat of DynamoDb is that it can be easily integrated with other AWS Services. You can trigger Lambda functions in the cloud every time a new item is created. If you care about reading a thing or two about Lambdas, we wrote a post about it recently. You can check it out here!

Cheers!

Share this post

Share this link via

Or copy link