Question

Difficulty: MediumData Store Operations with Amazon DynamoDB

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?

  1. Create a Global Secondary Index (GSI) with FlightID as the partition key and ReservationStatus as the sort key.Answer
  2. Perform a Query operation on the GSI using a key condition expression to specify the FlightID and ReservationStatus.Answer
  3. C
    Perform a Scan operation on the base table using a FilterExpression to filter items where the FlightID and ReservationStatus match.
  4. D
    Increase the base table's provisioned Read Capacity Units (RCUs) to mitigate ProvisionedThroughputExceededException errors when performing the daily full table Scan.
  5. E
    Initialize 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

1
Analyze the table's primary key and the query requirements.
The table's partition key is ReservationID, but the query requires filtering by FlightID and ReservationStatus, which are non-key attributes in the base table.
DynamoDB does not allow direct Query operations on non-key attributes without an index.
2
Select the appropriate indexing strategy.
Create a Global Secondary Index (GSI) with FlightID as the partition key and ReservationStatus as the sort key.
A GSI allows querying across partition keys different from the base table, enabling direct lookups by FlightID.
3
Execute the retrieval operation.
Perform a Query operation on the GSI with a key condition expression.
Querying is more efficient than scanning because it only consumes capacity units for the matching items.

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