Amazon DynamoDB
Developer Guide (API Version 2012-08-10)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Step 2: Create Example Tables

The getting started example covers the two following simple use cases.

Use case 1: Product Catalog

Suppose you want to store product information in DynamoDB. Each product you store has its own set of properties, and accordingly, you need to store different information about each of these products. DynamoDB is a NoSQL database: Except for a required common primary key, individual items in a table can have any number of attributes. This enables you to save all the product data in the same table. So you will create a ProductCatalog table that uses Id as the primary key and stores information for products such as books and bicycles in the table. Id is a numeric attribute and hash type primary key. After creating the table, in the next step you will write code to retrieve items from this table. Note that while you can retrieve an item, you cannot query the table. To query the table, the primary key must be of the hash and range type.

Table NamePrimary Key TypeHash Attribute Name and TypeRange Attribute Name and TypeProvisioned Throughput
ProductCatalog (Id, ... )Hash

Attribute Name: Id

Type: Number

-

Read capacity units: 10

Write capacity units: 5

Use case 2: Forum Application

Amazon Web Services maintains several forums (see Discussion Forums) for customers to engage with the developer community, ask questions, or reply to other customer queries. AWS maintains one or more forums for each of its services. Customers go to a forum and start a thread by posting a message. Over time, each thread receives one or more replies.

In this exercise, we model this application by creating the three following tables. Note that the Thread and Reply tables have hash and range type primary keys and therefore you can query these tables.

Table NamePrimary Key TypeHash Attribute Name and TypeRange Attribute Name and TypeProvisioned Throughput
Forum (Name, ... )Hash

Attribute Name: Name

Type: String

-

Read capacity units: 10

Write capacity units: 5

Thread (ForumName, Subject, ... )Hash and Range

Attribute Name: ForumName

Type: String

Attribute Name: Subject

Type: String

Read capacity units: 10

Write capacity units: 5

Reply (Id, ReplyDateTime, ... ) Hash and Range

Attribute Name: Id

Type: String

Attribute Name: ReplyDateTime

Type: String

Read capacity units: 10

Write capacity units: 5

The Reply table has the following local secondary index:

Index NameAttribute to IndexProjected Attributes
PostedByIndexPostedByTable and Index Keys

In the next step, you will write a simple query to retrieve data from these tables.

Creating Tables

You can create tables using either the DynamoDB console or write code using the DynamoDB API. For this getting started, you will use the console to create the tables. These tables are also used in other sections of this guide.

Note

In these getting started steps, you use these tables to explore some of the basic DynamoDB operations. However, these tables are also used in other examples throughout this reference. If you delete these tables and later want to recreate them, you can repeat this getting started step, or programmatically recreate them and upload sample data. For more information about creating the tables and loading the data programmatically, see Creating Example Tables and Uploading Data.

To Create the Sample Tables

Use the following procedure to create the four tables.

  1. Sign in to the AWS Management Console and open the Amazon DynamoDB console at https://console.aws.amazon.com/dynamodb/.

    For first time users, the following wizard opens.

    If you already have tables in DynamoDB, you'll see the console with your list of tables.

  2. Click Create Table.

    The Create Table wizard opens.

  3. Set the table name and its primary key

    1. Specify the table name in the Table Name field.

      See the preceding table for the list of tables that you are creating.

    2. Select the primary key type.

      See the preceding table for the primary key type of the table that you are creating.

    3. If the table's primary key is of Hash and Range type, specify the hash attribute name and type for both the hash and range attributes.

    4. If the table's primary key is of Hash type, specify the hash attribute name and select the attribute type.

    5. Click Continue.

  4. For the Reply table, create a local secondary index.

    A local secondary index allows you to perform queries against an attribute that is not part of the primary key. For this exercise, you will create a local secondary index on the PostedBy attribute of the Reply table.

    1. In the Attribute to Index field, enter PostedBy.

    2. In the Index Name field, enter PostedByIndex.

    3. In the Projected Attributes field, select Table and Index Keys.

    4. Click Add Index.

    5. Click Continue.

  5. Specify the provisioned throughput

    1. In the Create Table - Provisioned Throughput step, leave the Help me estimate Provisioned Throughput checkbox unchecked.

      It is important to configure the appropriate provisioned throughput based on your expected item size and your expected read and write request rates. There is cost associated with the configured provisioned throughput. For more information, see Specifying Read and Write Requirements for Tables. However, for the getting started exercise, you will set finite values.

    2. In the Read Capacity Units field, enter 10. In the Write Capacity Units field, enter 5 and click Continue.

      These throughput values allow you up to ten 4 KB read operations and up to five 1 KB write operations per second. For more information, see DynamoDB Data Model.

  6. Configure CloudWatch Alarms

    In the Create Table - Throughput Alarms (optional) wizard, select the Use Basic Alarms check box.

    This automatically configures CloudWatch alarms to notify you when your consumption reaches 80% of the table's provisioned throughput. By default, the alarm is set to send an email to the AWS Account email address that you are using to create the table. You can edit the Send notification to: text box and specify additional email addresses that are separated by commas.

    When you delete the table using the console, you can optionally delete the associated CloudWatch alarms.

    For more information about CloudWatch alarms, see the Amazon CloudWatch Developer Guide.

  7. Click Create Table.

    Repeat the procedure to create the remaining tables.

    The console shows the list of tables. You must wait for the status of all the tables to become Active. The console also shows the Details, Monitoring, and Alarm Setup tabs that provide additional information about the selected table.