DVA-C02 · Question #376
A developer manages an application that writes customer orders to an Amazon DynamoDB table. The orders use customer_id as the partition key, order_id as the sort key, and order_date as an attribute. A
The correct answer is C. Add a new global secondary index (GSI) to the DynamoDB table that specifies order_date as the. A Global Secondary Index (GSI) with order_date as the partition key enables efficient Query operations for the new access pattern, since the base table's partition key (customer_id) cannot serve queries by order_date.
Question
A developer manages an application that writes customer orders to an Amazon DynamoDB table. The orders use customer_id as the partition key, order_id as the sort key, and order_date as an attribute. A new access pattern requires accessing data by order_date and order_id. The developer needs to implement a new AWS Lambda function to support the new access pattern. How should the developer support the new access pattern in the MOST operationally efficient way?
Options
- AAdd a new local secondary index (LSI) to the DynamoDB table that specifies order_date as the
- BWrite the new Lambda function to scan the DynamoDB table. In the Lambda function, write a
- CAdd a new global secondary index (GSI) to the DynamoDB table that specifies order_date as the
- DEnable DynamoDB Streams on the table. Choose the new and old images information to write to
How the community answered
(45 responses)- A2% (1)
- B11% (5)
- C80% (36)
- D7% (3)
Why each option
A Global Secondary Index (GSI) with order_date as the partition key enables efficient Query operations for the new access pattern, since the base table's partition key (customer_id) cannot serve queries by order_date.
An LSI must use the same partition key as the base table (customer_id); it cannot be configured with order_date as a new partition key, so it cannot support queries by order_date alone.
Scanning the entire DynamoDB table and filtering in Lambda code is extremely inefficient for large datasets and increases both latency and cost.
Adding a GSI with order_date as the partition key and order_id as the sort key allows the new Lambda function to Query the GSI directly by order_date and optionally filter or sort by order_id. This is the most operationally efficient approach because it avoids table scans and does not require restructuring the base table.
Enabling DynamoDB Streams creates an event stream for change data capture; it does not create a query index and cannot satisfy a read-based access pattern by order_date and order_id.
Concept tested: DynamoDB GSI for new query access patterns
Source: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html
Community Discussion
No community discussion yet for this question.