AWS Certified Developer – Associate / Question #1108 of 557

Question #1108

An application includes an Amazon DynamoDB table named transactions. The table has a primary partition key of transactionId and a global secondary index (GSI) named userIndex. The GSI has a partition key of userId and a sort key of transactionDate.

A developer needs to create an AWS Lambda function to retrieve the transactions that have a userId of 200.

Which solution will meet this requirement by using the LEAST read capacity?

A

Define a DynamoDB API request for the GetItem action with the following parameters:

B

Define a DynamoDB API request for the BatchGetItem action with the following parameters:

C

Define a DynamoDB API request for the Scan action with the following parameters:

D

Define a DynamoDB API request for the Query action with the following parameters:

Explanation

The correct answer is D because:
1. Query Action: The Query action is designed to retrieve items from a DynamoDB table or index based on the partition key (and optionally a sort key). Since the GSI 'userIndex' uses 'userId' as its partition key, querying this index with 'userId=200' directly targets the relevant items, minimizing read capacity usage.
2. Avoid Full Scans: A Scan (option C) reads the entire table/index, consuming excessive read capacity. GetItem (A) and BatchGetItem (B) require exact primary keys, which are not provided here.
3. GSI Efficiency: Querying the GSI ensures only the necessary items are read, aligning with DynamoDB's best practices for cost and performance.

Key Points:
- Use Query for partition key-based retrievals.
- Avoid Scan for large datasets due to higher RCU consumption.
- GSIs enable efficient query patterns on non-primary key attributes.

Answer

The correct answer is: D