A developer is building a fleet management system that tracks real-time vehicle locations. The telemetry data is stored in an Amazon DynamoDB table with `VehicleID` as the partition key and `Timestamp` as the sort key. The developer needs to retrieve the location data for a specific vehicle over the past hours. Which of the following approaches should the developer use to retrieve this data with the lowest latency and minimal Read Capacity Unit (RCU) consumption?
- APerform a Scan operation on the table with a filter expression specifying both the VehicleID and a range comparison on the Timestamp.
- BConfigure the AWS SDK client with hardcoded access keys to scan the table and filter the location records in the application memory.
- Perform a Query operation on the table with a key condition expression specifying the VehicleID and a range comparison on the Timestamp.Cevap
- DCreate a Global Secondary Index (GSI) with Timestamp as the partition key, and perform a Query on the GSI for the specific vehicle.
Cevap
Perform a Query operation on the table with a key condition expression specifying the VehicleID and a range comparison on the Timestamp.
Performing a Query operation on the table with a key condition expression specifying the partition key (VehicleID) and a range comparison on the sort key (Timestamp) is the most efficient method. DynamoDB queries target only the physical partition where the specific partition key's items reside and read the sorted items sequentially, consuming Read Capacity Units (RCUs) proportional only to the returned items.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query vs Scan efficiency and primary key design.
Tahmini Süre:1m 30s