Q24 — AWS DVA-C02 Ch.1

Question 24 of 100 | ← Chapter 1

A developer manages an application that inserts customer orders into an Amazon DynamoDB table. 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 querying by `order_date` and `order_id`. The developer needs to implement a new AWS Lambda function to support this access pattern. How should the developer support the new access pattern in the most operationally efficient way?

Correct Answer: C. Add a new global secondary index (GSI) to the DynamoDB table, specifying `order_date` as the partition key and `order_id` as the sort key. Write a new Lambda function to query the new GSI.

Explanation

Option C is correct: a global secondary index (GSI) allows efficient querying using attributes other than the base table’s primary key. Since the new access pattern requires querying by `order_date` (not the partition key) and `order_id` (not the sort key), a GSI with `order_date` as partition key and `order_id` as sort key enables direct, low-latency queries. LSIs (option A) require the same partition key as the base table, making them unsuitable. Scanning (option B) is inefficient and costly at scale. Streams (option D) capture change events—not queryable data—and cannot satisfy ad-hoc queries by `order_date` and `order_id`.