A developer is designing the backend for an IoT vehicle tracking application. The application processes telemetry data from active vehicles. The data is written to an Amazon DynamoDB table using `VehicleId` as the partition key and `Timestamp` as the sort key.
The application must support the following access patterns:
1. Retrieve only the single most recent telemetry record for a specific vehicle.
2. Retrieve all telemetry records across all vehicles that have returned a status of `Error` within the last hours.
Which two actions should the developer take to meet these requirements with the lowest latency and cost? (Select TWO.)
- Perform a `Query` operation on the main table with `VehicleId` as the partition key, set `ScanIndexForward` to `false`, and set the `Limit` parameter to .Cevap
- Create a Global Secondary Index (GSI) with `ErrorStatus` (a sparse attribute only present when the status is an error) as the partition key and `Timestamp` as the sort key, and query this GSI using a key condition expression.Cevap
- CPerform a `Scan` operation on the main table with a FilterExpression to find the most recent telemetry record for a specific vehicle.
- DInitialize the DynamoDB client inside the AWS Lambda function code by hardcoding a temporary IAM user's credentials to authenticate the API calls.
- EIncrease the table's provisioned write capacity units (WCUs) to resolve any `ProvisionedThroughputExceededException` errors caused by reading telemetry data from a small number of frequently accessed vehicles.
Cevap
The correct options are performing a Query operation on the main table with VehicleId as the partition key, ScanIndexForward set to false, and a Limit of 1; and creating a Global Secondary Index with ErrorStatus as the partition key and Timestamp as the sort key, and querying it using a key condition expression.
To retrieve the single most recent telemetry record for a specific vehicle with the lowest latency and cost, a Query operation is the most efficient choice because it target-scans a single partition. By setting ScanIndexForward to false, the results are returned in descending order of the sort key (Timestamp), and setting the Limit parameter to 1 ensures that only the newest single item is read and returned, minimizing Read Capacity Unit (RCU) consumption. To retrieve all error records across all vehicles within the last 24 hours, a Global Secondary Index (GSI) is required since the query must span multiple vehicle partitions. Defining a GSI with ErrorStatus (a sparse attribute only present on error records) as the partition key and Timestamp as the sort key ensures that only error records are indexed, and queries can filter on the Timestamp in the key condition expression rather than post-query.
Adım Adım Çözüm
Anahtar Kavram
DynamoDB Query vs Scan optimization and credential management in SDK clients
Tahmini Süre:2m 0s