Question

Difficulty: EasyData Store Operations with Amazon DynamoDB

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 EmployeeIdEmployeeId and the sort key is ProjectNameProjectName. 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?

  1. Perform a Query operation using the partition key EmployeeIdEmployeeId in the KeyConditionExpression.Answer
  2. B
    Perform a Scan operation using a FilterExpression on the partition key EmployeeIdEmployeeId.
  3. C
    Perform a Scan operation after initializing the DynamoDB client with hardcoded AWS access keys inside the application code.
  4. D
    Create a Global Secondary Index with a static partition key value for all items, and perform a Query on that index.

Answer

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.

Step-by-Step Solution

1
Identify the data retrieval requirement
The developer needs to fetch all projects assigned to a single employee.
This establishes that we have a known partition key value (EmployeeIdEmployeeId) and want to retrieve a subset of items sharing that key.
2
Compare Query and Scan operations in DynamoDB
A Query directly accesses the physical partition associated with the partition key, whereas a Scan reads every single item in the table.
To minimize latency and RCU consumption, the Query operation must be selected instead of the Scan operation.
3
Formulate the Query parameter
Use the KeyConditionExpression with the partition key equal to the target value.
This ensures DynamoDB retrieves only the items matching the partition key without scanning unnecessary data.

Key Concept

DynamoDB Query vs Scan optimization
Rate this question