A developer is designing a flight booking platform where reservation records are stored in an Amazon DynamoDB table. The table's partition key is `ReservationID`. The application needs to retrieve all reservations for a specific `FlightID` that currently have a `ReservationStatus` of 'Pending'. The solution must be highly efficient, minimize read latency, and avoid unnecessary read capacity consumption. Which two actions should the developer take to meet these requirements?
- Create a Global Secondary Index (GSI) with FlightID as the partition key and ReservationStatus as the sort key.Answer
- Perform a Query operation on the GSI using a key condition expression to specify the FlightID and ReservationStatus.Answer
- CPerform a Scan operation on the base table using a FilterExpression to filter items where the FlightID and ReservationStatus match.
- DIncrease the base table's provisioned Read Capacity Units (RCUs) to mitigate ProvisionedThroughputExceededException errors when performing the daily full table Scan.
- EInitialize the AWS SDK client inside the application code by hardcoding the access keys of an IAM user that has read access to the table.
Answer
To retrieve the pending reservations efficiently, the developer must create a Global Secondary Index (GSI) with FlightID as the partition key and ReservationStatus as the sort key, and then perform a Query operation on this GSI.
To retrieve items efficiently using attributes other than the base table's partition key, a Global Secondary Index (GSI) must be created. Setting FlightID as the partition key and ReservationStatus as the sort key of the GSI allows direct querying. Performing a Query operation on this GSI with a key condition expression retrieves only the matching items, minimizing latency and RCU consumption.
Step-by-Step Solution
Key Concept
Using Global Secondary Indexes (GSIs) to perform efficient Query operations instead of Scan operations on non-key attributes in Amazon DynamoDB.
Estimated Time:2m 0s