A developer is writing a backend service for a task management application. The application stores user tasks in an Amazon DynamoDB table with UserId as the partition key and TaskId as the sort key. The developer needs to retrieve all tasks associated with a specific UserId that have a status of 'Pending'. The developer wants to minimize latency and the consumption of Read Capacity Units (RCUs).
Which two actions should the developer take to retrieve the required items efficiently? (Select TWO.)
- Perform a Query operation specifying the UserId in the key condition expression.Answer
- Use a FilterExpression in the Query operation to return only tasks with a status of 'Pending'.Answer
- CPerform a Scan operation on the table and apply a FilterExpression for UserId and status.
- DUse the GetItem API operation specifying only the UserId parameter.
- EHardcode AWS access keys in the application client to bypass standard IAM role credential retrieval.
Answer
To retrieve the tasks efficiently, the developer should perform a Query operation specifying the UserId in the key condition expression, and use a FilterExpression in that Query operation to filter for tasks with a status of 'Pending'.
The most efficient way to retrieve multiple items sharing the same partition key (UserId) is to perform a Query operation. A FilterExpression can then be applied to the Query operation to narrow down the results to only include those where the status is 'Pending'. This ensures only the relevant partition is read, minimizing RCU consumption and latency.
Step-by-Step Solution
Key Concept
Efficient data retrieval using DynamoDB Query and FilterExpressions