Question

Difficulty: EasyData Store Operations with Amazon DynamoDB

A developer is building a school administration web portal. The portal needs to retrieve a student's list of registered courses from an Amazon DynamoDB table. The table is designed with `StudentId` as the partition key and `CourseId` as the sort key. Which DynamoDB operation is the most efficient and cost-effective way to retrieve all courses for a specific student?

  1. A
    Perform a `Scan` operation and use a filter expression to return only items matching the `StudentId`.
  2. B
    Perform a `Scan` operation to retrieve all items and filter the courses on the client side in application memory.
  3. Perform a `Query` operation specifying the `StudentId` in the key condition expression.Answer
  4. D
    Perform a `Scan` operation and increase the provisioned Read Capacity Units (RCUs) of the table to prevent read throughput throttling.

Answer

Perform a `Query` operation specifying the `StudentId` in the key condition expression.
The correct answer is the option proposing a `Query` operation because a `Query` operation allows direct retrieval of items that share the same partition key (`StudentId`). This is highly efficient and consumes Read Capacity Units (RCUs) only for the items returned.

Step-by-Step Solution

1
Analyze the table schema and the query requirements.
The table schema has a composite primary key consisting of a partition key (`StudentId`) and a sort key (`CourseId`). The requirement is to retrieve all courses for a single student.
Understanding the key structure helps determine which DynamoDB operations are supported and most efficient.
2
Evaluate the difference between Query and Scan operations for partition key lookup.
A `Query` operation directly targets the partition key, retrieving only matching items. A `Scan` operation reads the entire table and then filters the results.
Choosing `Query` over `Scan` minimizes the data read from disk, saving performance overhead and cost.
3
Select the optimal DynamoDB API call.
The `Query` API call with a key condition expression for `StudentId` retrieves all courses for that student in a single, efficient request.
This matches best practices for querying composite primary key tables.

Key Concept

Query vs Scan operations in Amazon DynamoDB
Estimated Time:45s
Rate this question