0
0
DynamoDBquery~30 mins

Scan with filter expressions in DynamoDB - Mini Project: Build & Apply

Choose your learning style9 modes available
Scan with filter expressions
📖 Scenario: You are managing a DynamoDB table that stores information about books in a library. Each book has attributes like Title, Author, and Year. You want to find books published after the year 2000.
🎯 Goal: Build a DynamoDB scan operation with a filter expression to retrieve only books published after the year 2000.
📋 What You'll Learn
Create a dictionary called table_data with three books, each having Title, Author, and Year attributes.
Create a variable called year_threshold and set it to 2000.
Write a scan operation using a filter expression that selects books with Year greater than year_threshold.
Add the final step to execute the scan and store the filtered results in a variable called filtered_books.
💡 Why This Matters
🌍 Real World
Filtering data in DynamoDB tables is common when you want to retrieve only relevant items without fetching the entire table.
💼 Career
Understanding scan operations with filter expressions is essential for backend developers and database administrators working with AWS DynamoDB.
Progress0 / 4 steps
1
Create the initial table data
Create a dictionary called table_data with these exact entries: {'BookID1': {'Title': 'The Hobbit', 'Author': 'J.R.R. Tolkien', 'Year': 1937}, 'BookID2': {'Title': 'Harry Potter and the Goblet of Fire', 'Author': 'J.K. Rowling', 'Year': 2000}, 'BookID3': {'Title': 'The Da Vinci Code', 'Author': 'Dan Brown', 'Year': 2003}}
DynamoDB
Need a hint?

Use a dictionary with keys as book IDs and values as dictionaries of book attributes.

2
Set the year threshold
Create a variable called year_threshold and set it to 2000.
DynamoDB
Need a hint?

Just assign the number 2000 to the variable year_threshold.

3
Write the scan with filter expression
Write a scan operation using a filter expression that selects books with Year greater than year_threshold. Use a variable called filtered_books to store the filtered results. Use a dictionary comprehension to filter table_data where the book's Year is greater than year_threshold.
DynamoDB
Need a hint?

Use a dictionary comprehension with for book_id, info in table_data.items() and filter with if info['Year'] > year_threshold.

4
Complete the scan operation
Add the final step to execute the scan and store the filtered results in a variable called filtered_books. Ensure the code includes the full dictionary comprehension filtering table_data by Year greater than year_threshold.
DynamoDB
Need a hint?

The final step is to have the filtered_books variable assigned with the filtered dictionary comprehension.