A developer is building a mobile application that stores user profile information in an Amazon DynamoDB table. The table uses UserId as the partition key. The developer needs to retrieve the profile details of a specific user with a known UserId in the most cost-effective and low-latency way possible.
Which two API operations or practices should the developer use to achieve this?
- Perform a GetItem API call specifying the UserId primary key to retrieve the exact user profile.Cevap
- Perform a Query API call using a key condition expression to search for the specific UserId.Cevap
- CPerform a Scan API call with a filter expression matching the specific UserId to filter the results.
- DPerform a Scan API call to retrieve the entire table, then filter the target UserId in application memory.
- EHardcode the AWS access key and secret key in the client configuration to eliminate IAM role assumption latency.
Cevap
Retrieve the item using either the GetItem operation targeting the primary key, or the Query operation with a key condition expression matching the partition key.
The correct approach involves retrieving data directly by the partition key to minimize read capacity consumption and latency. The GetItem operation retrieves a single item based on its primary key and is the most efficient way to access a single record. Alternatively, the Query operation uses a key condition expression to retrieve items that share the same partition key, which is also highly efficient because it only reads the partition containing the matching partition key.
Adım Adım Çözüm
Anahtar Kavram
Efficient DynamoDB retrieval using primary keys (GetItem and Query) versus inefficient scans.