Question

Difficulty: HardData Store Operations with Amazon DynamoDB

A developer is designing the backend for an IoT vehicle tracking application. The application processes telemetry data from 15,00015,000 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 2424 hours.

Which two actions should the developer take to meet these requirements with the lowest latency and cost? (Select TWO.)

  1. Perform a `Query` operation on the main table with `VehicleId` as the partition key, set `ScanIndexForward` to `false`, and set the `Limit` parameter to 11.Answer
  2. 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.Answer
  3. C
    Perform a `Scan` operation on the main table with a FilterExpression to find the most recent telemetry record for a specific vehicle.
  4. D
    Initialize the DynamoDB client inside the AWS Lambda function code by hardcoding a temporary IAM user's credentials to authenticate the API calls.
  5. E
    Increase 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.

Answer

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.

Step-by-Step Solution

1
Optimize the retrieval of the most recent record for a specific vehicle.
A query operation is formulated on the primary key (VehicleId) with the sort key (Timestamp) sorted in descending order (ScanIndexForward=false) and a limit of 1.
This reads only the single most recent item, consuming minimal read capacity.
2
Optimize the retrieval of error records across all vehicles.
A Global Secondary Index (GSI) is configured with ErrorStatus as the partition key and Timestamp as the sort key.
Since ErrorStatus is only populated on error records, the index is sparse, reducing storage/indexing costs and allowing fast queries across all vehicle partition keys using the sort key.
3
Ensure secure access to DynamoDB from the Lambda function.
The DynamoDB SDK client is initialized without hardcoded credentials, utilizing the environment's IAM execution role.
This adheres to the principle of least privilege and avoids exposing static credentials.

Key Concept

DynamoDB Query vs Scan optimization and credential management in SDK clients
Estimated Time:2m 0s
Rate this question