Amazon DynamoDB
Developer Guide (API Version 2012-08-10)

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

Step 1: Create Example Tables

In this section, you use the AWS Management Console to create tables in 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: Id (Number)

Use Case 2: Forum Application

Suppose that you want to build an application for message boards or discussion forums. AWS Discussion Forums represent one example of such an application. Customers can engage with the developer community, ask questions, or reply to other customers' posts. Each AWS service has a dedicated forum. Anyone can start a new discussion thread by posting a message in a forum. Each thread might receive any number of replies.

You can model this application by creating three tables: Forum, Thread, and Reply.

Table Name Primary Key
Forum

Partition key: Name (String)

Thread

Partition key: ForumName (String)

Sort key: Subject (String)

Reply

Partition key: Id (String)

Sort key: ReplyDateTime (String)

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: PostedBy (String)

Sort key: Message (String)

Create the ProductCatalog Table

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.

  2. Choose Create Table.

  3. In the Create DynamoDB table screen, do the following:

    1. On the Table name box, enter ProductCatalog.

    2. For the Primary key, in the Partition key box, enter Id. Set the data type to Number.

  4. When the settings are as you want them, choose Create.

Create the Forum Table

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.

  2. Choose Create Table.

  3. In the Create DynamoDB table screen, do the following:

    1. In the Table name box, enter Forum.

    2. For the Primary key, in the Partition key box, enter Name. Set the data type to String.

  4. When the settings are as you want them, choose Create.

Create the Thread Table

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.

  2. Choose Create Table.

  3. In the Create DynamoDB table screen, do the following:

    1. In the Table name box, enter Thread.

    2. 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.

  4. When the settings are as you want them, choose Create.

Create the Reply Table

  1. Open the DynamoDB console at https://console.aws.amazon.com/dynamodb/.

  2. Choose Create Table.

  3. In the Create DynamoDB table screen, do the following:

    1. In the Table name box, enter Reply.

    2. 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.

    3. In the Table settings section, clear Use default settings.

    4. In the Secondary indexes section, choose Add index.

    5. 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.

  4. When the settings are as you want them, choose Create.