A developer is writing a backend application to retrieve a specific customer's order history from an Amazon DynamoDB table. The table uses CustomerId as the partition key and OrderId as the sort key. The application needs to fetch all orders for a single customer in the most efficient and cost-effective manner. Which API operation should the developer use to retrieve this data?
- APerform a Scan operation and use a filter expression to filter the results by CustomerId.
- BInitialize the DynamoDB client by embedding AWS access keys in the code to perform multiple parallel GetItem requests.
- Perform a Query operation specifying the CustomerId in the key condition expression.Cevap
- DIncrease the table's provisioned read capacity units (RCUs) to prevent throttling and perform a Scan operation.
Cevap
Perform a Query operation specifying the CustomerId in the key condition expression.
Performing a Query operation specifying the CustomerId in the key condition expression is the most efficient and cost-effective approach. DynamoDB Query operations search only the partition matching the partition key, returning all matching items while consuming only the RCUs required for the returned dataset.
Adım Adım Çözüm
Anahtar Kavram
Using Query instead of Scan to efficiently retrieve items with a shared partition key.