Step 1: Create example tables
In this section, you use the Amazon Web Services Management Console to create tables in Amazon DynamoDB for two simple use cases.
Use case 1: Product catalog
Suppose that you want to store product information in DynamoDB. Each product has its own distinct attributes, so you need to store different information about each of these products.
You can create a ProductCatalog
table, where each item is uniquely
identified by a single, numeric attribute: Id
.
Table name | Primary key |
---|---|
ProductCatalog |
Partition key: |
Use case 2: Forum application
Suppose that you want to build an application for message boards or discussion
forums. Amazon Discussion forums
You can model this application by creating three tables: Forum
,
Thread
, and Reply
.
Table name | Primary key |
---|---|
Forum |
Partition key: |
Thread |
Partition key: Sort key: |
Reply |
Partition key: Sort key: |
The Reply
table has a global secondary index named
PostedBy-Message-Index
. This index facilitates queries on
two non-key attributes of the Reply
table.
Index name | Primary key |
---|---|
PostedBy-Message-Index |
Partition key: Sort key: |
Create the ProductCatalog table
Open the DynamoDB console at https://console.amazonaws.cn/dynamodb/
. Choose Create Table.
-
In the Create DynamoDB table screen, do the following:
-
On the Table name box, enter
ProductCatalog
. -
For the Primary key, in the Partition key box, enter
Id
. Set the data type to Number.
-
-
When the settings are as you want them, choose Create.
Create the forum table
Open the DynamoDB console at https://console.amazonaws.cn/dynamodb/
. Choose Create Table.
-
In the Create DynamoDB table screen, do the following:
-
In the Table name box, enter
Forum
. -
For the Primary key, in the Partition key box, enter
Name
. Set the data type to String.
-
-
When the settings are as you want them, choose Create.
Create the thread table
Open the DynamoDB console at https://console.amazonaws.cn/dynamodb/
. Choose Create Table.
-
In the Create DynamoDB table screen, do the following:
-
In the Table name box, enter
Thread
. -
For the Primary key, do the following:
-
In the Partition key box, enter
ForumName
. Set the data type to String. -
Choose Add sort key.
-
In the Sort key box, enter
Subject
. Set the data type to String.
-
-
-
When the settings are as you want them, choose Create.
Create the reply table
Open the DynamoDB console at https://console.amazonaws.cn/dynamodb/
. Choose Create Table.
-
In the Create DynamoDB table screen, do the following:
-
In the Table name box, enter
Reply
. -
For the Primary key, do the following:
-
In the Partition key box, enter
Id
. Set the data type to String. -
Choose Add sort key.
-
In the Sort key box, enter
ReplyDateTime
. Set the data type to String.
-
-
In the Table settings section, clear Use default settings.
-
In the Secondary indexes section, choose Add index.
-
In the Add index window, do the following:
-
For the Primary key, do the following:
-
In the Partition key box, enter
PostedBy
. Set the data type to String. -
Choose Add sort key.
-
In the Sort key box, enter
Message
. Set the data type to String.
-
-
In the Index name box, enter
PostedBy-Message-Index
. -
Set the Projected attributes to All.
-
Choose Add index.
-
-
-
When the settings are as you want them, choose Create.