Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a logistics tracking application that stores package delivery status updates in an Amazon DynamoDB table. The table has a partition key of `PackageID` and a sort key of `StatusTimestamp`. The application needs to retrieve all delivery status updates for a specific `PackageID` that occurred within the last 2424 hours. The results must be returned starting with the most recent update first.

Which two actions should the developer take to meet these requirements with the lowest latency and minimal Read Capacity Unit (RCU) consumption? (Select TWO.)

  1. Use the `Query` API operation with a key condition expression specifying the `PackageID` and a range comparison on `StatusTimestamp`.Answer
  2. Set the `ScanIndexForward` parameter to `false` in the API request.Answer
  3. C
    Use the `Scan` API operation with a filter expression specifying the `PackageID` and `StatusTimestamp`.
  4. D
    Hardcode AWS credentials directly in the application's SDK client configuration to minimize authorization latency.
  5. E
    Increase the provisioned read capacity units (RCUs) for the table to prevent throttling when sorting the retrieved dataset.

Answer

Use the `Query` API operation with a key condition expression on the partition key and sort key, and set the `ScanIndexForward` parameter to `false` in the API request.
To retrieve items sharing the same partition key (`PackageID`) efficiently, the `Query` API operation should be used. The query can filter results by the sort key (`StatusTimestamp`) directly in the key condition expression, which consumes Read Capacity Units (RCUs) only for the items that match the criteria. By default, DynamoDB returns query results in ascending order of the sort key. Setting the `ScanIndexForward` parameter to `false` reverses this order, returning the most recent updates first.

Step-by-Step Solution

1
Determine the appropriate API operation for retrieving data with a known partition key.
Select the `Query` API operation rather than `Scan`.
A `Query` operation directly accesses the partition and filters by sort key efficiently, minimizing RCU consumption, whereas a `Scan` reads the entire table.
2
Configure the sorting order of the returned items.
Set the `ScanIndexForward` parameter to `false`.
DynamoDB sorts query results in ascending order of the sort key by default. Setting `ScanIndexForward` to `false` reverses the order to descending, returning the most recent items first.

Key Concept

Optimizing read operations in Amazon DynamoDB using Query instead of Scan and controlling sort order via ScanIndexForward.
Rate this question