Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

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

  1. Perform a Query operation specifying the DocumentID and the range of RevisionTimestamp in the KeyConditionExpression.Answer
  2. Set the ScanIndexForward parameter to false in the request to return the results in descending order of the sort key.Answer
  3. C
    Perform a Scan operation and use a FilterExpression to filter by DocumentID and RevisionTimestamp.
  4. D
    Perform a Scan operation and set the ScanIndexForward parameter to false to sort the results.
  5. E
    Initialize 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

1
Determine the optimal DynamoDB API operation to retrieve items with a known partition key.
Identify that a Query operation is much more efficient than a Scan operation since Query targets a single partition key, whereas Scan reads the entire table.
Minimizing RCU consumption and latency.
2
Formulate the search criteria using KeyConditionExpression.
Specify the DocumentID partition key as an exact match and add a condition on the RevisionTimestamp sort key (e.g., greater than or equal to the timestamp from 24 hours ago).
Applying the key conditions directly to the query index filter rather than post-filtering with a FilterExpression.
3
Configure the sort order of the returned items.
Set the ScanIndexForward parameter to false to reverse the default ascending sort order of the sort key to descending (newest first).
Meeting the requirement to return the revisions sorted from most recent to oldest.

Key Concept

Optimizing read operations in Amazon DynamoDB by using Query instead of Scan and leveraging the ScanIndexForward parameter to control sort order.
Rate this question