Question

Difficulty: EasyData Store Operations with Amazon DynamoDB

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?

  1. Perform a Query operation specifying the UserID in the key condition expression, and initialize the AWS SDK client using the default credential provider chain.Answer
  2. B
    Perform 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.
  3. C
    Perform 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.
  4. D
    Perform a Scan operation using a FilterExpression specifying the UserID, and initialize the AWS SDK client using the default credential provider chain.

Answer

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.

Step-by-Step Solution

1
Determine the optimal DynamoDB API operation to retrieve multiple items that share the same partition key.
The Query operation is selected because it directly targets the partition key and reads only the matching items.
Unlike Scan, which reads every item in the table, Query minimizes Read Capacity Unit consumption and request latency.
2
Identify the secure method for managing AWS credentials when initializing the SDK client.
The default credential provider chain is used to automatically load credentials from IAM roles or environment variables.
Hardcoding credentials in the code exposes sensitive access keys to repositories and unauthorized users.

Key Concept

DynamoDB Query operations and secure AWS SDK credential initialization

Alternative Method

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.
Estimated Time:45s
Rate this question