Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

A developer is building a digital coupon distribution service. The application stores coupon details in an Amazon DynamoDB table. The table uses CouponIDCouponID as the partition key and BatchIDBatchID as the sort key. The application needs to retrieve all coupons that belong to a specific CampaignNameCampaignName attribute to calculate current redemption metrics. The CampaignNameCampaignName 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?

  1. Create a Global Secondary Index (GSI) with CampaignNameCampaignName as the partition key, and perform a Query operation on the GSI.Answer
  2. B
    Perform a Scan operation on the base table and use a FilterExpression on the CampaignNameCampaignName attribute.
  3. C
    Hardcode access keys in the application SDK client initialization to bypass default IAM credential lookup and execute a Scan.
  4. D
    Increase 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 CampaignNameCampaignName 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

1
Analyze the table's access pattern and identify that retrieving items by a non-key attribute (CampaignNameCampaignName) across multiple CouponIDCouponID partitions is required.
Querying the base table directly is not possible because the partition key is CouponIDCouponID.
DynamoDB queries must specify the partition key of the table or index being searched.
2
Evaluate the difference between a Scan operation with a FilterExpression and a Query operation on a Global Secondary Index.
A Scan reads all items in the table and applies the filter afterward, consuming RCUs for the entire dataset. A Query on a GSI only reads the matching items.
Creating a GSI allows for efficient, targeted lookups on non-key attributes with minimal RCU consumption.
3
Define the GSI schema using CampaignNameCampaignName as the partition key.
The GSI isolates the relevant data, enabling a Query operation to fetch only the coupons associated with the specific CampaignNameCampaignName.
This strategy minimizes read latency and maximizes cost-efficiency by avoiding unnecessary scans.

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
Rate this question