A developer is building a dashboard for an IoT smart home application. The application must retrieve the status logs of a specific smart device (identified by `DeviceId`) over the past 24 hours from an Amazon DynamoDB table named `DeviceStatusLogs`. The table's primary key consists of `DeviceId` (partition key) and `Timestamp` (sort key). Which approach should the developer use to retrieve this data with the lowest latency and the most efficient use of Read Capacity Units (RCUs)?
- APerform a Scan operation on the table with a FilterExpression to filter the results by DeviceId and Timestamp.
- Perform a Query operation on the table with a KeyConditionExpression that specifies the DeviceId and a range condition on the Timestamp sort key.Cevap
- CInitialize the DynamoDB client by hardcoding AWS access keys in the application code, and perform a Query operation with a KeyConditionExpression.
- DPerform a Scan operation using parallel segments to retrieve the logs, and then filter by DeviceId and Timestamp in the application code.
Cevap
Perform a Query operation on the table with a KeyConditionExpression that specifies the DeviceId and a range condition on the Timestamp sort key.
The correct approach is to perform a Query operation on the table with a KeyConditionExpression that specifies the DeviceId partition key and a range condition on the Timestamp sort key. This allows DynamoDB to efficiently look up only the relevant items in the specific partition within the specified time range, consuming fewer RCUs and returning results with lower latency.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query vs Scan optimization and SDK credential best practices.
Tahmini Süre:1m 30s