A developer is building a digital coupon distribution service. The application stores coupon details in an Amazon DynamoDB table. The table uses as the partition key and as the sort key. The application needs to retrieve all coupons that belong to a specific attribute to calculate current redemption metrics. The attribute is not part of the primary key. Which DynamoDB operation or design configuration should the developer implement to retrieve this data with the lowest latency and minimal Read Capacity Unit (RCU) consumption?
- Create a Global Secondary Index (GSI) with as the partition key, and perform a Query operation on the GSI.Answer
- BPerform a Scan operation on the base table and use a FilterExpression on the attribute.
- CHardcode access keys in the application SDK client initialization to bypass default IAM credential lookup and execute a Scan.
- DIncrease the provisioned Read Capacity Units (RCUs) on the base table to prevent ProvisionedThroughputExceededException and continue using Scan operations.
Answer
Create a Global Secondary Index (GSI) with as the partition key, and perform a Query operation on the GSI.
Creating a Global Secondary Index (GSI) with the target query attribute as the partition key allows the application to perform a Query operation rather than a Scan. A Query operation in Amazon DynamoDB is highly efficient because it directly finds the target items using the index, consuming Read Capacity Units (RCUs) only for the returned items. This avoids scanning the entire base table, reducing both latency and operational costs.
Step-by-Step Solution
Key Concept
Using Global Secondary Indexes (GSIs) to optimize read queries on non-key attributes and minimize RCU usage compared to Scan operations.
Alternative Method
If campaign queries are extremely infrequent, using Amazon Athena with DynamoDB Federated Query could scan the data in place, though it does not resolve the high latency issue for active application paths.
Estimated Time:1m 30s