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
SongTitleas the sort key. -
Leave Default settings selected.
-
-
Choose Create to create the table.
-
Once the table is in
ACTIVEstatus, 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.
-
MusicArtistSongTitleFollow 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
AlbumTitleof type String. -
Enter the following values for your item:
-
For Artist, enter
No One You Knowas 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.
-
AwardsAlbumTitleNo One You KnowCall Me TodaySomewhat Famous1Acme BandHappy DaySongs About Life10Acme BandPartiQL RocksAnother Album Title8Step 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
ArtistandSongTitle. The first item in the list is the one with theArtistAcme Band and theSongTitleHappy 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
Artistvalue is Acme Band andSongTitlevalue is Happy Day. -
Update the AlbumTitle value to
Updated Album Title, and then choose Save.
Updated Album TitleStep 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 BandStep 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.
AlbumTitleAlbumTitle-indexStep 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 FamousStep 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
Musictable. -
Choose Delete table.
Thanks
For
Watching
Amazon DynamoDB - Hands On Demo
By Deepak Dubey
Amazon DynamoDB - Hands On Demo
- 315