Soru

Zorluk: KolayData Store Operations with Amazon DynamoDB

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?

  1. Perform a Query operation with a key condition expression specifying the DeviceID and a range condition on the Timestamp.Cevap
  2. B
    Perform a Scan operation with a filter expression specifying the DeviceID and the range of Timestamp values.
  3. C
    Perform a Scan operation using an AWS SDK client that is initialized with hardcoded AWS access keys.
  4. D
    Increase 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

1
Analyze the table key schema and the retrieval requirements.
The table has a composite primary key consisting of a partition key (DeviceID) and a sort key (Timestamp), and we need to retrieve items matching a specific partition key value within a range of sort key values.
Understanding the key structure helps determine which DynamoDB retrieval operations are valid and efficient.
2
Evaluate DynamoDB API operations for efficiency.
The Query operation allows retrieving all items that share the same partition key and filters them based on the sort key condition, without scanning other partitions. The Scan operation reads all items across the entire table, which is highly inefficient.
Selecting the operation that reads the minimum amount of data ensures low latency and low RCU consumption.
3
Formulate the correct operation parameters.
Use the Query API with a key condition expression specifying DeviceID = 'device-123' and a range condition on Timestamp between the start and end of the 24-hour window.
This retrieves only the requested records directly from the specific partition.

Anahtar Kavram

Efficient item retrieval using DynamoDB Query instead of Scan.
Tahmini Süre:45s
Bu soruyu puanla