Soru

Zorluk: Çok zorMessage-Based Integration using Amazon SQS and SNS

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?

  1. Set the MessageGroupId to the unique sensor identifier when publishing messages to the SNS FIFO topic to maintain message ordering per sensor.Cevap
  2. 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.Cevap
  3. C
    Decrease 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.
  4. D
    Migrate the message ingestion to an Amazon Kinesis Data Stream and set a static partition key for all fleet sensors to guarantee ordered processing.
  5. E
    Configure the AWS SDK client inside the Lambda function using hardcoded IAM user credentials to bypass IAM role assumption and decrease connection initiation latency.

Cevap

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.

Adım Adım Çözüm

1
Analyze the out-of-order execution issue for fleet sensors.
SQS FIFO queues guarantee ordering only within the scope of a specific MessageGroupId.
By grouping messages using the unique sensor identifier as the MessageGroupId, SQS guarantees that messages for a particular sensor are processed sequentially.
2
Analyze the duplicate entry issue caused by the Lambda consumer.
The Lambda function timeout is 60 seconds, which exceeds the SQS queue's visibility timeout of 30 seconds.
If a Lambda function takes longer than 30 seconds to process a message, the SQS visibility timeout expires, and the message returns to the queue. Other concurrent Lambda invocations can then poll and process the same message, causing duplicates.
3
Apply the AWS recommended formula for SQS visibility timeout when integrating with Lambda.
Increase the visibility timeout of the SQS queue to at least 6 times the Lambda function timeout (6 * 60 seconds = 360 seconds or 6 minutes).
This buffer prevents message reprocessing during long-running batch processing or execution retries.

Anahtar Kavram

FIFO Queue Ordering and Lambda Visibility Timeout Alignment
Tahmini Süre:3m 0s
Bu soruyu puanla