A logistics company uses a serverless transit-tracking application where fleet sensors publish real-time telemetry updates. The updates are published to an Amazon SNS FIFO topic, which is subscribed to by multiple Amazon SQS FIFO queues. An AWS Lambda function is configured to process messages from one of the SQS FIFO queues. The Lambda function has a timeout of 1 minute, while the SQS queue's visibility timeout is set to 30 seconds. During peak hours, the developer notices that some telemetry updates are processed out of order, and the database shows duplicate entries for the same sensor updates. Which two of the following configuration changes will resolve the out-of-order execution issues and prevent duplicate message processing?
- Set the MessageGroupId to the unique sensor identifier when publishing messages to the SNS FIFO topic to maintain message ordering per sensor.Answer
- Increase the SQS queue's visibility timeout to at least 6 minutes (6 times the Lambda function's timeout) to ensure messages are not reprocessed while the Lambda function is executing.Answer
- CDecrease the Lambda function's execution timeout to 15 seconds to ensure it always completes before the SQS queue's visibility timeout, without modifying the queue configuration.
- DMigrate the message ingestion to an Amazon Kinesis Data Stream and set a static partition key for all fleet sensors to guarantee ordered processing.
- EConfigure the AWS SDK client inside the Lambda function using hardcoded IAM user credentials to bypass IAM role assumption and decrease connection initiation latency.
Answer
The correct configuration changes are to set the MessageGroupId to the unique sensor identifier when publishing to the SNS FIFO topic, and to increase the SQS queue's visibility timeout to at least 6 minutes.
To fix the out-of-order execution, setting the MessageGroupId to the unique sensor identifier ensures that SQS FIFO groups related messages and processes them sequentially. To prevent duplicate executions, increasing the SQS queue's visibility timeout to at least 6 times the Lambda function timeout ensures the message remains invisible to other polling invocations while the current execution runs.
Step-by-Step Solution
Key Concept
FIFO Queue Ordering and Lambda Visibility Timeout Alignment
Estimated Time:3m 0s