Creating a DynamoDB Table

Steps to create a new table in DynamoDB, and populate it with some values.

Advertisements

Now it’s time to get cracking with DynamoDB.  DynamoDB is one of the services you can use with Amazon Web Services.

In order to access these, just go to http://aws.amazon.com.

If you’ve registered for it, you can log into the console at the top right hand side of the screen.  Once you did that you will see your console.  The top of the page will look a bit like the screenshot below.  I’ve added some extra buttons at the top, but what’s important is the region at the right hand side of the screen.

Schermafbeelding 2017-01-31 om 21.08.34.png

With me it’s set to “Oregon“.  Which was the default when I logged on.  It’s important you keep it at this one.  If you go and use one of the services in this region, and you switch to another region later on, you won’t see the tables you created for example.  Also, not all services are available in all regions.  So keep that in mind.

But before I begin, I want to create a new user that is able to connect to the service.  You can do that in another service called “IAM“.  Locate the IAM service in the services overview you can find by clicking the “Services” dropdown at the top left hand side of the screen.

Schermafbeelding 2017-01-31 om 19.13.16.png

In the screenshot above you can see my recently used services, and IAM is one of them.

If select it, you are able to create a user.

Schermafbeelding 2017-01-31 om 19.00.05.png

I will go ahead and do so by clicking the “Add user” button.  The system prompts me for a user name and I’ll call it “smartmirror“.

Schermafbeelding 2017-01-31 om 19.00.39.png

I made sure sure to click the “programmatic access” type in order to be able to connect with it from an external application.

Next, you’re able to give the user some permissions.

Schermafbeelding 2017-01-31 om 19.01.59.png

There are 3 ways to do so : by adding him to a group, by copying existing permissions, or by attaching policies.  I will choose the last one and search for the “AdministratorAccess” policy.  This will allow the user to do everything including create and drop tables, insert, query, etc.  Just click the checkbox and confirm.

When the process is complete you will see an overview like the one you see in the screenshot below.

Schermafbeelding 2017-01-31 om 19.02.32.png

 

You can see the user got a unique access key ID, and a secret.  These 2 things, we can use to connect to the mirror using the “smartmirror” user credentials.

Ok, so now it’s time to create a new table.

In fact, before doing so, you should familiarise yourself with the concept of a NoSQL database, because that’s what DynamoDB is.  It is very different from a relational database like the most of you will know in that sense that it is not optimised for storage, but rather for read speed.  In order to accomplish this, it uses a different technology in which the rows (or items if you want to call them) are stored in a JSON format in tables.  Unlike relational tables these tables hardly have a fixed structure.  The structure of the table can vary row per row (or item per item if you will).  Just google it, or watch some video tutorials on it.  Digging deeper is beyond the scope of this blog post.

So, go back to the console and this time choose the DynamoDB service.  If all is well you should get to a welcome page where you will be prompted to create your very first table.  Just click that button, and the page you will see next will resemble the one below.

Schermafbeelding 2017-01-31 om 19.16.17.png

You will have to choose a table name.  I called it “CommandQueue”.  This is the table in which I will store the commands issued to Alexa, and which are to be sent to the mirror.  Or rather, for which the mirror will poll.

I have to specify a partition key.  This is the primary key of the table.  I can also add a sort key, but that’s about it when it comes to metadata.  I call them “Session” and “Timestamp”.  Also keep the default settings activated, and click create.  The details of what a partition key and a sort key is, is beyond the scope of this article, so please google to get more information on the NoSQL principals for more info.

If all is well, that will bring to the the AWS DynamoDB console.  The interface will look similar to the screenshot below.  You can see the table was created, and there are currently no items in it.  Check it out by clicking the “Items” tab at the right hand side of the screen.

Schermafbeelding 2017-01-31 om 19.16.59.png

We will go ahead and add a new item.  In the interface you will be able to give a value for the Session and Timestamp attributes, but I can also add other parts, as I will do here.  I will add a “command”, as a string value, and set it to “HIDE-ALL-MODULES”.

Schermafbeelding 2017-01-31 om 19.19.01.png

Check out the result below.

Schermafbeelding 2017-01-31 om 19.19.11.png

Allright.  All ready now to start reading from the table.

 

 

2 thoughts on “Creating a DynamoDB Table”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s