-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

DynamoDB Cookbook
By :

Now that we have signed up for AWS, let's start by creating our first DynamoDB table using the DynamoDB console.
To perform this recipe, you need to have completed the earlier recipe of Signing up to the DynamoDB AWS console.
Let's create our first DynamoDB table. The steps are as follows:
product
table, which will save the products-related data for all the e-commerce websites.Here, we will create a table with the Primary Key Type as the Hash and Range composite keys. We will have the hash key
as the product id
and range key
as the product type
. Add the details, as shown in the following screenshot, and click on Continue:
Global/Local Secondary Indexes
. Here, we would like to query DynamoDB items with their name
and manufacturer
. So, we create an index, and click on the Add Index to Table button, as shown in the following screenshot. Once done, click on Continue to proceed with the next configuration:Here, we are also selecting Projected Attributes as All Attributes, as we would like DynamoDB to give us all the attributes back when we query it. Alternatively, if you know exactly what attributes you need to be projected into this secondary index, you can select Specify Attributes, in the Projected Attributes dropdown, and add the specific attributes you want to be projected.
In DynamoDB, we don't need to bother about the availability, scalability, and reliability of the table as it is completely owned by Amazon. We just need to create a table and start using it. We can modify the throughput units any time using the same console. This gives us the flexibility to control the reads and writes of the data from DynamoDB. For example, if you think that there is a certain period where you would be expecting more reads/writes, then you can increase the throughput values and vice versa. You can find out how AWS calculates the read and write throughput at
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ProvisionedThroughputIntro.html.
Choosing a right key is very important in order to balance the load on DynamoDB partitions. The hash key should be chosen in such a way that it has unique values in it so that the data can be distributed across the cluster. The range key should be chosen in such a way that items can be grouped together so that if you have any such queries, they will perform faster. This is why we have chosen the product id as the Hash Key attribute, while the product type as the Range Key attribute.
The same is the case with Global Secondary Indexes. The Global secondary indexes allow us to query items on non-primary key attributes. Here, we may want to query items on their names or group them by the manufacturer.
DynamoDB supports various data types for its attributes, which are as follows:
You can choose which suites you best.
Here, you might have noticed that instead of putting the manufacturer's name as a proper name to the range key in the Global Secondary Index, I chose to use its short form as mnfr
. The reason for this is that when it comes to key-value pair types of databases, the entries stored in the database are always both keys and values together. So, every time you add an item or an attribute, it will be saved as key=value
in the database. So, it's the best practice to use short yet meaningful names for keys and attributes. We will discuss such best practices in Chapter 7, DynamoDB Best Practices.
Change the font size
Change margin width
Change background colour