Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

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 100100 transactions. A new feature requires retrieving all transactions for a specific account where the transaction amount is greater than 500 USD500\text{ USD}. Which approach should the developer use to retrieve this data while minimizing read latency and Read Capacity Unit (RCU) consumption?

  1. Perform a Query operation specifying the AccountID in the key condition expression, and apply a filter expression on the transaction amount attribute.Cevap
  2. B
    Perform a Scan operation on the entire table using a filter expression to filter by both AccountID and the transaction amount attribute.
  3. C
    Increase 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.
  4. D
    Hardcode 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.

Cevap

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.

Adım Adım Çözüm

1
Analyze the table primary key design and requirements.
The table partition key is AccountID, and the query needs to retrieve data for a specific account.
Identifying the partition key helps determine if a Query operation is possible, as Query requires an equality match on the partition key.
2
Compare Query and Scan operations.
A Query only reads items matching the specified partition key, while a Scan reads the entire table.
Since the partition key is known and each account has few transactions, Query is significantly more efficient than Scan.
3
Determine how to handle the non-key attribute filter (amount > 500 USD).
Use a FilterExpression to evaluate the transaction amount after the Query returns the partition's items.
Since the amount is not part of the primary key, it cannot be used in the KeyConditionExpression directly. Using a FilterExpression in a Query confines the read operation to just the specific account's items.

Anahtar Kavram

Using Query instead of Scan for DynamoDB item retrieval when the partition key is known.
Tahmini Süre:1m 30s
Bu soruyu puanla