Soru

Zorluk: OrtaData Store Operations with Amazon DynamoDB

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)?

  1. A
    Perform a Scan operation on the table with a FilterExpression to filter the results by DeviceId and Timestamp.
  2. Perform a Query operation on the table with a KeyConditionExpression that specifies the DeviceId and a range condition on the Timestamp sort key.Cevap
  3. C
    Initialize the DynamoDB client by hardcoding AWS access keys in the application code, and perform a Query operation with a KeyConditionExpression.
  4. D
    Perform 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

1
Identify the primary key structure of the target DynamoDB table.
The table has a composite primary key: `DeviceId` as the partition key and `Timestamp` as the sort key.
This tells us we can perform query operations that target specific partitions and sort ranges directly.
2
Evaluate DynamoDB operations to find the most efficient method for retrieving specific items.
A Query operation allows us to specify the partition key exactly and apply comparison operators on the sort key.
This ensures DynamoDB only reads physical items matching the partition key and the time range, minimizing RCU consumption.
3
Construct the Query parameters with KeyConditionExpression.
Set `KeyConditionExpression` to `DeviceId = :devId AND #ts >= :startTime`.
This targets the specific device and filters the timestamp range at the storage layer prior to returning data.

Anahtar Kavram

DynamoDB Query vs Scan optimization and SDK credential best practices.
Tahmini Süre:1m 30s
Bu soruyu puanla