A developer is writing a backend service for an internal corporate directory application. The application stores employee project assignments in an Amazon DynamoDB table where the partition key is and the sort key is . The developer needs to retrieve all project assignments for a single specific employee. Which approach should the developer take to retrieve this data in the most cost-effective and performant manner?
- Perform a Query operation using the partition key in the KeyConditionExpression.Cevap
- BPerform a Scan operation using a FilterExpression on the partition key .
- CPerform a Scan operation after initializing the DynamoDB client with hardcoded AWS access keys inside the application code.
- DCreate a Global Secondary Index with a static partition key value for all items, and perform a Query on that index.
Cevap
Perform a Query operation using the partition key EmployeeId in the KeyConditionExpression.
The Query operation is the most efficient and cost-effective method to find items sharing the same partition key. It restricts its search to the single partition holding the partition key value and returns only the matching items, which consumes minimal Read Capacity Units (RCUs) and completes with low latency.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query vs Scan optimization