Soru

Zorluk: KolayData Store Operations with Amazon DynamoDB

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.)

  1. Perform a Query operation specifying the UserId in the key condition expression.Cevap
  2. Use a FilterExpression in the Query operation to return only tasks with a status of 'Pending'.Cevap
  3. C
    Perform a Scan operation on the table and apply a FilterExpression for UserId and status.
  4. D
    Use the GetItem API operation specifying only the UserId parameter.
  5. E
    Hardcode AWS access keys in the application client to bypass standard IAM role credential retrieval.

Cevap

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.

Adım Adım Çözüm

1
Determine the appropriate DynamoDB API operation.
Since the developer has the partition key (UserId) and wants to retrieve all matching items, the Query operation is the correct choice. GetItem cannot retrieve multiple items without the sort key, and Scan reads the entire table which is inefficient.
Using Query minimizes Read Capacity Unit (RCU) consumption by targeting only the specific partition.
2
Apply the filter for non-key attributes.
Since 'status' is not part of the primary key, a FilterExpression must be added to the Query operation to filter out items where the status is not 'Pending'.
FilterExpression is applied after the query reads the partition, reducing the payload size returned to the application.

Anahtar Kavram

Efficient data retrieval using DynamoDB Query and FilterExpressions
Bu soruyu puanla