A developer is implementing a microservice for a digital library system. The system needs to retrieve a specific book's metadata using its ISBN (which is the primary key) and retrieve a list of all reviews for a specific book, sorted by the review date.
Which two DynamoDB operations should the developer use to retrieve this data most efficiently with the lowest Read Capacity Unit (RCU) consumption?
- Use the GetItem operation to retrieve the book's metadata by its ISBN.Answer
- Use the Query operation to retrieve the reviews for a specific book using its partition key.Answer
- CUse the Scan operation with a filter expression on the ISBN to retrieve the book's metadata.
- DUse the Scan operation to retrieve all reviews in the table and filter them on the client side.
- EHardcode the AWS credentials in the SDK client configuration to speed up authentication for DynamoDB calls.
Answer
The developer should use the GetItem operation to retrieve the book's metadata and the Query operation to retrieve the reviews.
To retrieve a single item by its primary key (ISBN), the GetItem operation is the most direct and efficient option. To retrieve multiple related items (reviews for a book) that share a partition key, the Query operation reads only the matching items, optimizing performance and RCU usage.
Step-by-Step Solution
Key Concept
Retrieving items from Amazon DynamoDB efficiently using GetItem and Query operations instead of Scan operations.