A retail company uses Amazon DynamoDB to store product catalog data. The table has a partition key of ProductID and a sort key of Category. The company needs to retrieve all products in a specific category, sorted by ProductID. Which operation should be used?
A GSI allows querying on non-primary key attributes. By setting Category as the partition key and ProductID as the sort key, you can efficiently query all products in a category, sorted by ProductID. This is the optimal solution for this access pattern.
Why this answer
To efficiently retrieve all products in a specific category sorted by ProductID, a global secondary index (GSI) is needed. The GSI should use Category as the partition key and ProductID as the sort key. This allows Query operations on the GSI to return the desired items in sorted order, leveraging DynamoDB's indexing capabilities for performance and cost efficiency.
Exam trap
The trap here is assuming that a Scan with a filter or a Query on the base table can satisfy the access pattern, when in fact the base table's key schema does not support querying by Category with sorting by ProductID.