A developer is building a smart home application that records temperature readings from IoT sensors. The data is stored in an Amazon DynamoDB table where the partition key is `SensorID` and the sort key is `Timestamp`. The developer needs to retrieve all readings for a specific `SensorID` where the recorded temperature is greater than . Which approach is the most efficient and cost-effective way to retrieve this data?
- Perform a Query operation specifying the SensorID in the KeyConditionExpression, and use a FilterExpression to return only the items where the temperature is greater than 25.Cevap
- BPerform a Scan operation with a FilterExpression to check both the SensorID and whether the temperature is greater than 25.
- CPerform a Scan operation on the table and initialize the DynamoDB client in the application code using hardcoded AWS credentials to perform the temperature filtering.
- DPerform a Scan operation on the table, and resolve any resulting ProvisionedThroughputExceededException errors by increasing the provisioned Read Capacity Units (RCUs) of the table.
Cevap
Perform a Query operation specifying the SensorID in the KeyConditionExpression, and use a FilterExpression to return only the items where the temperature is greater than 25.
The Query operation is the most efficient and cost-effective method to retrieve items that share a common partition key. By specifying the partition key (SensorID) in the KeyConditionExpression, DynamoDB directly accesses the partition containing the target items. The FilterExpression is then applied to the non-key temperature attribute to filter the results before they are returned to the application, minimizing payload size.
Adım Adım Çözüm
Anahtar Kavram
Using the Query operation with a KeyConditionExpression for the partition key and a FilterExpression for non-key attributes is the most efficient retrieval method in DynamoDB.