A developer is designing a vehicle tracking system where telemetry data is written to an Amazon DynamoDB table. Each item contains VehicleID (partition key), Timestamp (sort key), Speed, FuelLevel, and GeoLocation. The application needs to retrieve telemetry records for a specific vehicle within a specific -hour window where the vehicle's speed exceeds , while minimizing read latency and resource consumption. Which two actions should the developer take to achieve this?
- Perform a Query operation specifying the VehicleID in the KeyConditionExpression and a range condition on Timestamp.Answer
- Apply a FilterExpression in the Query operation to filter the retrieved records by the speed attribute before returning them.Answer
- CPerform a Scan operation with a FilterExpression containing the VehicleID, Timestamp, and speed attributes.
- DIncrease the provisioned read capacity units (RCUs) of the table to mitigate throttling errors caused by high-volume queries on a single vehicle ID.
- EInitialize the DynamoDB client by hardcoding temporary AWS credentials directly in the application code to minimize authentication overhead.
Answer
Perform a Query operation specifying the VehicleID in the KeyConditionExpression and a range condition on Timestamp, and apply a FilterExpression in the Query operation to filter the retrieved records by the speed attribute before returning them.
To retrieve records for a specific partition key (VehicleID) and a range of sort keys (Timestamp) efficiently, a Query operation should be used. The KeyConditionExpression specifies the partition key equality and the sort key range. To filter the returned items by a non-key attribute (Speed), a FilterExpression is applied. This filters the data on the server side before returning it to the client, minimizing the payload size.
Step-by-Step Solution
Key Concept
Using Query operations with KeyConditionExpression and FilterExpression to optimize data retrieval in Amazon DynamoDB