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:
Sign in to the AWS Management Console and open the DynamoDB console at https://console.aws.amazon.com/dynamodb/
. -
In the left navigation pane, choose Tables.
-
Choose Create table.
-
Enter the Table details as follows:
-
For Table name, enter
Music
. -
For Partition key, enter
Artist
. -
For Sort key, enter
SongTitle
.
-
-
For Table settings, keep the default selection of Default settings.
-
Choose Create table to create the table.
-
Once the table is in
ACTIVE
status, we recommend that you enable Point-in-time recovery for DynamoDB on the table by performing the following steps:-
Choose the table name to open the table.
-
Choose Backups.
-
Choose Edit in the Point-in-time recovery (PITR) section.
-
On the Edit point-in-time recovery settings page, choose Turn on point-in-time recovery.
-
Choose Save changes.
-
The following AWS CLI example creates a new Music
table using
create-table
.
Linux
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
Windows CMD
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": { "AttributeDefinitions": [ { "AttributeName": "Artist", "AttributeType": "S" }, { "AttributeName": "SongTitle", "AttributeType": "S" } ], "TableName": "Music", "KeySchema": [ { "AttributeName": "Artist", "KeyType": "HASH" }, { "AttributeName": "SongTitle", "KeyType": "RANGE" } ], "TableStatus": "CREATING", "CreationDateTime": "2023-03-29T12:11:43.379000-04:00", "ProvisionedThroughput": { "NumberOfDecreasesToday": 0, "ReadCapacityUnits": 5, "WriteCapacityUnits": 5 }, "TableSizeBytes": 0, "ItemCount": 0, "TableArn": "arn:aws:dynamodb:us-east-1:111122223333:table/Music", "TableId": "60abf404-1839-4917-a89b-a8b0ab2a1b87", "TableClassSummary": { "TableClass": "STANDARD" } } } }
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.
Linux
aws dynamodb describe-table --table-name Music | grep TableStatus
Windows CMD
aws dynamodb describe-table --table-name Music | findstr 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",
Once the table is in ACTIVE
status, it's considered best practice
to enable Point-in-time recovery for DynamoDB on the table by running the following
command:
Linux
aws dynamodb update-continuous-backups \ --table-name Music \ --point-in-time-recovery-specification \ PointInTimeRecoveryEnabled=true
Windows CMD
aws dynamodb update-continuous-backups --table-name Music --point-in-time-recovery-specification PointInTimeRecoveryEnabled=true
This command returns the following result.
{ "ContinuousBackupsDescription": { "ContinuousBackupsStatus": "ENABLED", "PointInTimeRecoveryDescription": { "PointInTimeRecoveryStatus": "ENABLED", "EarliestRestorableDateTime": "2023-03-29T12:18:19-04:00", "LatestRestorableDateTime": "2023-03-29T12:18:19-04:00" } } }
Note
There are cost implications to enabling continuous backups with
point-in-time recovery. For more information about pricing, see Amazon DynamoDB
pricing
After creating the new table, proceed to Step 2: Write data to a table using the console or AWS CLI.