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 . 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?
- APerform a Scan operation on the table using a FilterExpression to filter by both EngagementID and Status.
- Perform a Query operation specifying the EngagementID in the KeyConditionExpression and a FilterExpression for the Status attribute.Cevap
- CInitialize 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.
- DPerform 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.
Cevap
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.
Adım Adım Çözüm
Anahtar Kavram
Using Query instead of Scan operations to retrieve items from a specific partition in Amazon DynamoDB to optimize read performance and cost.
Tahmini Süre:1m 30s