A developer is building a backend for a recipe sharing application. The application needs to retrieve a single recipe's details from an Amazon DynamoDB table by providing the exact `RecipeId` (which is the table's partition key). Which approach should the developer use to retrieve this item most efficiently with the lowest latency and read capacity unit (RCU) consumption?
- APerform a Scan operation with a filter expression matching the RecipeId.
- Perform a GetItem operation using the specific RecipeId.Answer
- CPerform a GetItem operation, but hardcode the AWS access keys in the client initialization to bypass default IAM credential lookup.
- DPerform a Query operation and scale up the table's overall provisioned read capacity to avoid hot partition throttling.
Answer
Perform a GetItem operation using the specific RecipeId.
The correct approach is to perform a GetItem operation using the specific RecipeId. In Amazon DynamoDB, GetItem is the most efficient method for retrieving a single item when the full primary key (the partition key in this case) is known. It directly retrieves the item without scanning other data, minimizing latency and RCU consumption.
Step-by-Step Solution
Key Concept
Selecting the most efficient DynamoDB operation for single-item retrieval using a primary key.