Amazon DynamoDB - Hands On Demo
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
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
. -
Enter
SongTitle
as the sort key. -
Leave Default settings selected.
-
-
Choose Create to create the table.
-
Once the table is in
ACTIVE
status, it's considered best practice to enable Point-in-time recovery for DynamoDB on the table by performing the following steps:-
Click the table name to open the table.
-
Click Backups.
-
Click the Edit button in the Point-in-time recovery section.
-
Click the checkbox to turn on point-in-time recovery, then click the Save changes button.
-
Music
Artist
SongTitle
Follow these steps to write data to the Music
table using the DynamoDB console.
-
In the navigation pane on the left side of the console, choose Tables.
-
In the table list, choose the Music table.
-
Select Explore Table Items.
-
In the Items view, choose Create item.
-
Choose Add new attribute, and then choose Number. Name the field
Awards
. -
Repeat this process to create an
AlbumTitle
of type String. -
Enter the following values for your item:
-
For Artist, enter
No One You Know
as the value. -
For SongTitle, enter
Call Me Today
. -
For AlbumTitle, enter
Somewhat Famous
. -
For Awards, enter
1
.
-
-
Choose Create item.
-
Repeat this process and create another item with the following values:
-
For Artist, enter
Acme Band
. -
For SongTitle enter
Happy Day
. -
For AlbumTitle, enter
Songs About Life
. -
For Awards, enter
10
.
-
-
Do this one more time to create another item with the same Artist as the previous step, but different values for the other attributes:
-
For Artist, enter
Acme Band
. -
For SongTitle enter
PartiQL Rocks
. -
For AlbumTitle, enter
Another Album Title
. -
For Awards, enter
8
.
-
Awards
AlbumTitle
No One You Know
Call Me Today
Somewhat Famous
1
Acme Band
Happy Day
Songs About Life
10
Acme Band
PartiQL Rocks
Another Album Title
8
Step 3: Read data from a table
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Select the Explore table items.
-
On the Items tab, view the list of items stored in the table, sorted by
Artist
andSongTitle
. The first item in the list is the one with theArtist
Acme Band and theSongTitle
Happy Day.
Step 4: Update data in a table
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Choose View items.
-
Choose the item whose
Artist
value is Acme Band andSongTitle
value is Happy Day. -
Update the AlbumTitle value to
Updated Album Title
, and then choose Save.
Updated Album Title
Step 5: Query data in a table
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Choose View items.
-
Choose Query.
-
For Partition key, enter
Acme Band
, and then choose Run.
Acme Band
Step 6: Create a global secondary index
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Choose the Indexes tab for the Music table.
-
Choose Create index.
-
For the Partition key, enter
AlbumTitle
. -
For Index name, enter
AlbumTitle-index
. -
Leave the other settings on their default values and choose Create index.
AlbumTitle
AlbumTitle-index
Step 7: Query the global secondary index
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Select the View items.
-
Choose Query.
-
In the drop-down list under Query, choose AlbumTitle-index.
For AlbumTitle, enter
Somewhat Famous
, and then choose Run.
Somewhat Famous
Step 8: clean up resources
-
In the navigation pane on the left side of the console, choose Tables.
-
Choose the Music table from the table list.
-
Choose the Indexes tab for the
Music
table. -
Choose Delete table.
Thanks
For
Watching
Amazon DynamoDB - Hands On Demo
By Deepak Dubey
Amazon DynamoDB - Hands On Demo
- 49