A smart-home application stores hourly temperature readings from thousands of devices in an Amazon DynamoDB table. The table is configured with DeviceID as the partition key and Timestamp as the sort key. A developer needs to retrieve all temperature readings for a specific device, 'device-123', that were recorded over the last 24 hours. Which DynamoDB API operation and configuration should the developer use to perform this retrieval with the lowest latency and cost?
- Perform a Query operation with a key condition expression specifying the DeviceID and a range condition on the Timestamp.Cevap
- BPerform a Scan operation with a filter expression specifying the DeviceID and the range of Timestamp values.
- CPerform a Scan operation using an AWS SDK client that is initialized with hardcoded AWS access keys.
- DIncrease the provisioned Read Capacity Units (RCUs) and perform a Scan operation across the entire table.
Cevap
Perform a Query operation with a key condition expression specifying the DeviceID and a range condition on the Timestamp.
A Query operation is the most efficient and cost-effective approach. Since the partition key (DeviceID) is known, a Query operation directly targets the partition containing the data. Using a range condition on the sort key (Timestamp) allows DynamoDB to read only the items within the desired 24-hour window, minimizing latency and the consumption of Read Capacity Units (RCUs).
Adım Adım Çözüm
Anahtar Kavram
Efficient item retrieval using DynamoDB Query instead of Scan.
Tahmini Süre:45s