Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

A developer is building a supply chain shipment tracking application that stores transit logs in an Amazon DynamoDB table. Each item contains metadata about a shipment, including ShipmentID (partition key), TransitTime (sort key), and the current WarehouseID where the shipment is located. The application needs to retrieve all transit logs for a specific shipment that occurred within the last 48 hours. The table contains over 10 million items. Which of the following approaches is the most performant and cost-effective method to retrieve the required transit logs?

  1. Perform a Query operation on the table using a KeyConditionExpression for the ShipmentID and a range comparison on the TransitTime attribute.Cevap
  2. B
    Perform a Scan operation on the table and use a FilterExpression on ShipmentID and TransitTime to filter the results before returning them to the application.
  3. C
    Perform a Scan operation, and resolve any resulting ProvisionedThroughputExceededException by increasing the table's provisioned Read Capacity Units (RCUs).
  4. D
    Perform a Scan operation, but initialize the AWS SDK client with hardcoded AWS access keys directly in the initialization code to bypass IAM role evaluation overhead.

Cevap

Perform a Query operation on the table using a KeyConditionExpression for the ShipmentID and a range comparison on the TransitTime attribute.
Performing a Query operation with a KeyConditionExpression is the most performant and cost-effective approach. DynamoDB directly targets the partition associated with the partition key (ShipmentID) and uses the sort key (TransitTime) to narrow down the results, consuming RCUs only for the items read rather than the entire table.

Adım Adım Çözüm

1
Analyze the table's key schema and query requirements.
The table has ShipmentID as the partition key and TransitTime as the sort key. The search requires finding logs for a specific ShipmentID within a specific TransitTime range.
Understanding the key structure determines if we can perform a direct key-based lookup (Query) or if a full-table Scan is required.
2
Evaluate the performance and cost impact of the Query operation compared to the Scan operation.
A Query only reads the items in the specific ShipmentID partition. A Scan reads all 10 million items in the table, incurring excessive costs and latency.
Selecting Query over Scan is the standard best practice for retrieving items sharing the same partition key.
3
Formulate the final API request using KeyConditionExpression.
A Query with a KeyConditionExpression specifying the ShipmentID and a range condition on TransitTime is identified as the optimal method.
This guarantees that DynamoDB only reads the subset of items that match the criteria, maximizing performance and minimizing RCUs.

Anahtar Kavram

Selecting Query over Scan for efficient data retrieval in DynamoDB using the primary key structure.
Bu soruyu puanla