Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a document management system for a consulting firm where client engagement files are stored in an Amazon DynamoDB table. The table is structured with `EngagementID` as the partition key and `FileID` as the sort key. The table size is approximately 50 GB50\text{ GB}. The developer needs to implement a feature that retrieves all files for a specific engagement that have a status of 'NeedsReview'. Which approach represents the most performant and cost-effective method to retrieve these records?

  1. A
    Perform a Scan operation on the table using a FilterExpression to filter by both EngagementID and Status.
  2. Perform a Query operation specifying the EngagementID in the KeyConditionExpression and a FilterExpression for the Status attribute.Answer
  3. C
    Initialize the AWS SDK client by hardcoding the IAM Access Key ID and Secret Access Key directly in the initialization code, and then execute a Scan operation on the table.
  4. D
    Perform a Scan operation on the table with a ProjectionExpression to retrieve only the Status attribute, and then filter for the 'NeedsReview' value in the application code.

Answer

Perform a Query operation specifying the EngagementID in the KeyConditionExpression and a FilterExpression for the Status attribute.
The correct approach uses the Query API operation. Because the partition key (EngagementID) is known, Query restricts the search to only the partition containing the target files, drastically reducing the number of Read Capacity Units (RCUs) consumed. Applying a FilterExpression further narrows down the returned items to only those with the status 'NeedsReview' without scanning the rest of the table.

Step-by-Step Solution

1
Identify the primary key structure of the table.
The table has a composite primary key consisting of EngagementID as the partition key and FileID as the sort key.
Knowing the primary key structure helps determine if a Query operation can be performed instead of a Scan.
2
Determine the query path for retrieving a specific engagement's files.
Since the partition key (EngagementID) is known, a Query operation can target a specific partition directly.
Using Query is much more efficient than Scan because DynamoDB only reads items that match the specified partition key value.
3
Apply filtering for the status attribute.
Use a FilterExpression to evaluate the Status attribute, ensuring only files with 'NeedsReview' are returned to the client.
This reduces the payload size sent over the network, while KeyConditionExpression keeps the read operations localized to the partition.

Key Concept

Using Query instead of Scan operations to retrieve items from a specific partition in Amazon DynamoDB to optimize read performance and cost.
Estimated Time:1m 30s
Rate this question