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.
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:
-
Sign in to the AWS Management Console and open the DynamoDB console at https://console.aws.amazon.com/dynamodb/
. -
In the navigation pane on the left side of the console, choose Dashboard.
-
On the right side of the console, choose Create Table.
-
Enter the table details as follows:
-
For the table name, enter
Music
. -
For the partition key, enter
Artist
. -
Choose Add sort key.
-
Enter
SongTitle
as the sort key.
-
-
Choose Create to create the table.
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.