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 Amazon Web Services Management Console and open the DynamoDB console at https://console.amazonaws.cn/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
. -
Enter
SongTitle
as the sort key. -
Leave Default settings selected.
-
-
Choose Create to create the table.
The following Amazon 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=5,WriteCapacityUnits=5 \ --table-class STANDARD
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": 5 }, "TableClassSummary": { "LastUpdateDateTime": 1558028402.69, "TableClass": "STANDARD" }, "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 Amazon CLI.