A developer is building a collaborative document editing application that stores revision history in an Amazon DynamoDB table. The table, named `DocumentRevisions`, uses `DocumentID` as the partition key and `RevisionTimestamp` (representing Unix epoch time in milliseconds) as the sort key. The developer needs to implement a feature to retrieve all revisions for a specific document created within the last hours, sorted from most recent to oldest. Which combination of actions should the developer take to achieve this with the best performance and minimal resource utilization? (Select TWO.)
- Perform a Query operation specifying the DocumentID and the range of RevisionTimestamp in the KeyConditionExpression.Answer
- Set the ScanIndexForward parameter to false in the request to return the results in descending order of the sort key.Answer
- CPerform a Scan operation and use a FilterExpression to filter by DocumentID and RevisionTimestamp.
- DPerform a Scan operation and set the ScanIndexForward parameter to false to sort the results.
- EInitialize the AWS SDK client inside the application code by hardcoding a dedicated IAM user's credentials to bypass the default credential provider chain for faster reads.
Answer
Perform a Query operation specifying the DocumentID and the range of RevisionTimestamp in the KeyConditionExpression, and set the ScanIndexForward parameter to false in the request to return the results in descending order of the sort key.
To retrieve revisions for a specific document within a certain time window in descending order, the developer should use a Query operation with a KeyConditionExpression containing the partition key (DocumentID) and a range condition on the sort key (RevisionTimestamp). Since Query returns items in ascending order of the sort key by default, setting ScanIndexForward to false reverses the order to descending, returning the most recent revisions first.
Step-by-Step Solution
Key Concept
Optimizing read operations in Amazon DynamoDB by using Query instead of Scan and leveraging the ScanIndexForward parameter to control sort order.