A developer is building a movie ticket booking platform. The ticket reservation details are stored in an Amazon DynamoDB table with as the partition key. To generate real-time metrics, the application must frequently retrieve all reservations associated with a specific . The query must be highly performant and cost-effective as the database grows.
Which solution meets these requirements with the lowest latency and resource 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 using a FilterExpression on the attribute to retrieve the matching reservations.
- CInitialize the AWS SDK client by hardcoding temporary credentials in the application source code to perform parallel Scan operations on the base table.
- DIncrease the provisioned Read Capacity Units (RCUs) on the base table to resolve any throughput throttling, and continue to run Scan operations to filter by .
Answer
Create a Global Secondary Index (GSI) with the target query attribute 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 is the correct approach. It enables the application to use the Query API instead of Scan, ensuring that only the items associated with the target attribute value are read. This consumes minimal Read Capacity Units (RCUs) and executes with low, predictable latency regardless of the table's overall size.
Step-by-Step Solution
Key Concept
Using Global Secondary Indexes (GSIs) and Query operations to efficiently retrieve data from Amazon DynamoDB tables on non-primary key attributes.