0
0
DynamoDBquery~30 mins

Sort key purpose and usage in DynamoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Sort Key Purpose and Usage in DynamoDB
📖 Scenario: You are building a simple online bookstore database using DynamoDB. You want to organize books by their genre and then by their publication year within each genre.
🎯 Goal: Create a DynamoDB table with a partition key and a sort key to store books by genre and publication year. Then, add items to the table and query books by genre sorted by year.
📋 What You'll Learn
Create a DynamoDB table named Books with Genre as the partition key and Year as the sort key.
Add at least three book items with the same genre but different years.
Write a query to retrieve all books of a specific genre sorted by year.
💡 Why This Matters
🌍 Real World
Organizing data in DynamoDB using partition and sort keys helps efficiently store and retrieve related items, such as books by genre and year.
💼 Career
Understanding partition and sort keys is essential for designing scalable and performant NoSQL databases in cloud applications.
Progress0 / 4 steps
1
Create DynamoDB table with partition key and sort key
Create a DynamoDB table named Books with Genre as the partition key (string) and Year as the sort key (number).
DynamoDB
Need a hint?

Use aws dynamodb create-table command with --key-schema specifying HASH for partition key and RANGE for sort key.

2
Add book items with same genre but different years
Add three book items to the Books table with Genre set to Fiction and Year values 2010, 2015, and 2020. Include an attribute Title with any book names.
DynamoDB
Need a hint?

Use aws dynamodb put-item command to add each book with the specified Genre and Year.

3
Query books by genre sorted by year
Write a DynamoDB query command to get all books where Genre is Fiction. The results should be sorted by Year in ascending order (default).
DynamoDB
Need a hint?

Use aws dynamodb query with --key-condition-expression to filter by Genre. Results are sorted by Year automatically.

4
Explain the purpose of the sort key in this table
Add a comment line explaining that the Year sort key allows storing multiple books in the same Genre partition and sorting them by publication year.
DynamoDB
Need a hint?

Write a comment starting with # explaining that the sort key helps organize items with the same partition key and sorts them.