A developer is building a corporate timesheet application where employee hours are stored in an Amazon DynamoDB table. The table uses `EmployeeID` as the partition key and `LogDate` as the sort key. The application needs to retrieve and display a list of all work logs for a specific employee during the month of June 2026. The operation must be optimized to minimize latency and Read Capacity Unit (RCU) consumption.
Which DynamoDB configuration and operation should the developer use to retrieve this data?
- Perform a Query operation using the KeyConditionExpression parameter to specify both the EmployeeID partition key and a range condition on the LogDate sort key.Answer
- BPerform a Query operation using the KeyConditionExpression parameter to specify the EmployeeID partition key, and apply a FilterExpression to filter the LogDate range.
- CPerform a Scan operation using the FilterExpression parameter to specify both the EmployeeID partition key and the LogDate range.
- DPerform a Scan operation with a ProjectionExpression to limit the returned attributes to EmployeeID and LogDate, then filter the logs on the client side.
Answer
Perform a Query operation using the KeyConditionExpression parameter to specify both the EmployeeID partition key and a range condition on the LogDate sort key.
The correct option is the one suggesting a Query operation with KeyConditionExpression for both the partition and sort keys. In DynamoDB, a Query operation finds items based on primary key values. By specifying both the partition key (EmployeeID) and a range condition on the sort key (LogDate) in the KeyConditionExpression, DynamoDB only reads the items that match both conditions. This minimizes the number of items read from physical storage, resulting in low latency and minimal Read Capacity Unit (RCU) consumption.
Step-by-Step Solution
Key Concept
DynamoDB Query operations and RCU optimization via KeyConditionExpression