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.
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.
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.
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“.
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.
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.
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.
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.
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”.
Check out the result below.
Allright. All ready now to start reading from the table.