Question

Difficulty: EasyData Store Operations with Amazon DynamoDB

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?

  1. A
    Perform a Scan operation and use a filter expression to filter the results by CustomerId.
  2. B
    Initialize the DynamoDB client by embedding AWS access keys in the code to perform multiple parallel GetItem requests.
  3. Perform a Query operation specifying the CustomerId in the key condition expression.Answer
  4. D
    Increase the table's provisioned read capacity units (RCUs) to prevent throttling and perform a Scan operation.

Answer

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.

Step-by-Step Solution

1
Identify the table's primary key structure.
The partition key is CustomerId and the sort key is OrderId.
Understanding the key schema helps determine which DynamoDB operations can target specific items directly.
2
Evaluate the retrieval requirement.
We need to fetch all orders for a single CustomerId.
Since the search is filtered by the partition key, we can retrieve all items under that partition without scanning the rest of the table.
3
Select the most efficient DynamoDB API operation.
Choose the Query API, passing the CustomerId in the key condition expression.
A Query operation retrieves items directly from the partition associated with the specified partition key, consuming minimal Read Capacity Units (RCUs) compared to a Scan.

Key Concept

Using Query instead of Scan to efficiently retrieve items with a shared partition key.
Rate this question