Step 1: Create a Table - Amazon DynamoDB

Step 1: Create a Table

In this step, you create a Music table in Amazon DynamoDB. The table has the following details:

  • Partition key — Artist

  • Sort key — SongTitle

For more information about table operations, see Working with Tables and Data in DynamoDB.

Note

Before you begin, make sure that you followed the steps in Prerequisites - Getting Started Tutorial.

To create a new Music table using the DynamoDB console:

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

  2. In the navigation pane on the left side of the console, choose Dashboard.

  3. On the right side of the console, choose Create Table.

    
                                Console screenshot showing the Create table button.
  4. Enter the table details as follows:

    1. For the table name, enter Music.

    2. For the partition key, enter Artist.

    3. Choose Add sort key.

    4. Enter SongTitle as the sort key.

  5. Choose Create to create the table.

    
                                Console screenshot showing the Create table page with fields
                                    completed.

The following AWS CLI example creates a new Music table using create-table.

aws dynamodb create-table \ --table-name Music \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=10,WriteCapacityUnits=5

Using create-table returns the following sample result.

{ "TableDescription": { "TableArn": "arn:aws:dynamodb:us-west-2:522194210714:table/Music", "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "WriteCapacityUnits": 5, "ReadCapacityUnits": 10 }, "TableSizeBytes": 0, "TableName": "Music", "TableStatus": "CREATING", "TableId": "d04c7240-0e46-435d-b231-d54091fe1017", "KeySchema": [ { "KeyType": "HASH", "AttributeName": "Artist" }, { "KeyType": "RANGE", "AttributeName": "SongTitle" } ], "ItemCount": 0, "CreationDateTime": 1558028402.69 } }

Note that the value of the TableStatus field is set to CREATING.

To verify that DynamoDB has finished creating the Music table, use the describe-table command.

aws dynamodb describe-table --table-name Music | grep TableStatus

This command returns the following result. When DynamoDB finishes creating the table, the value of the TableStatus field is set to ACTIVE.

"TableStatus": "ACTIVE",

After creating the new table, proceed to Step 2: Write Data to a Table Using the Console or AWS CLI.