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?
- APerform a `Scan` operation and use a filter expression to return only items matching the `StudentId`.
- BPerform a `Scan` operation to retrieve all items and filter the courses on the client side in application memory.
- Perform a `Query` operation specifying the `StudentId` in the key condition expression.Answer
- DPerform 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
Key Concept
Query vs Scan operations in Amazon DynamoDB
Estimated Time:45s