A developer is building a backend service that retrieves user profile history records from an Amazon DynamoDB table. The table is configured with UserID as the partition key and LastUpdated as the sort key. The developer wants to retrieve all historical records for a specific UserID using the AWS SDK. Which approach should the developer use to perform this retrieve operation most efficiently and securely?
- Perform a Query operation specifying the UserID in the key condition expression, and initialize the AWS SDK client using the default credential provider chain.Cevap
- BPerform a Scan operation and filter the results by UserID in the application code, and initialize the AWS SDK client using the default credential provider chain.
- CPerform a Query operation specifying the UserID in the key condition expression, and initialize the AWS SDK client by hardcoding the AWS Access Key ID and Secret Access Key.
- DPerform a Scan operation using a FilterExpression specifying the UserID, and initialize the AWS SDK client using the default credential provider chain.
Cevap
Perform a Query operation specifying the UserID in the key condition expression, and initialize the AWS SDK client using the default credential provider chain.
The correct approach retrieves the historical records using the Query API since it directly queries the table using the partition key, ensuring minimal Read Capacity Unit consumption. It also secures the application by utilizing the default credential provider chain to handle authentication.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query operations and secure AWS SDK credential initialization
Alternatif Yöntem
If only a single specific historical record is needed and both the partition key and sort key are known, the GetItem API operation would be the most efficient approach.
Tahmini Süre:45s