A developer is designing a financial ledger application that stores transaction data in an Amazon DynamoDB table named `AccountLedger`. The table has `AccountID` as the partition key and `TransactionTimestamp` as the sort key. The table contains millions of items, but each individual account has fewer than transactions. A new feature requires retrieving all transactions for a specific account where the transaction amount is greater than . Which approach should the developer use to retrieve this data while minimizing read latency and Read Capacity Unit (RCU) consumption?
- Perform a Query operation specifying the AccountID in the key condition expression, and apply a filter expression on the transaction amount attribute.Answer
- BPerform a Scan operation on the entire table using a filter expression to filter by both AccountID and the transaction amount attribute.
- CIncrease the table's provisioned Read Capacity Units (RCUs) to prevent throttling, and perform a Scan operation with a filter expression for AccountID and the transaction amount.
- DHardcode a temporary IAM User access key in the application's client configuration, and perform a Scan operation on the table to locate the target transactions.
Answer
Perform a Query operation specifying the AccountID in the key condition expression, and apply a filter expression on the transaction amount attribute.
The correct approach is to perform a Query operation specifying the AccountID in the key condition expression, and apply a filter expression on the transaction amount attribute. A Query operation is highly efficient because it targets only the partition containing the target AccountID. Even though the filter expression on the amount is evaluated after the items are read from the partition, the number of read operations is limited to the transactions of that single account (fewer than 100 items), minimizing read latency and RCU consumption.
Step-by-Step Solution
Key Concept
Using Query instead of Scan for DynamoDB item retrieval when the partition key is known.
Estimated Time:1m 30s