Soru

Zorluk: OrtaMessage-Based Integration using Amazon SQS and SNS

A developer is designing an IoT home alert system. When a sensor detects an anomaly, it publishes a message to an Amazon SNS topic. An Amazon SQS queue is subscribed to this topic to buffer messages for an AWS Lambda function that processes alerts and notifies users. The Lambda function takes up to 2020 seconds to process a single message and send notifications. Currently, the SQS queue's Visibility Timeout is set to 1515 seconds, and the Lambda function's timeout is set to 3030 seconds. Users are receiving duplicate alert notifications for the same event. Which modification should the developer make to resolve the duplicate notifications?

  1. A
    Increase the Amazon SQS queue's visibility timeout to 2525 seconds so that it exceeds the maximum processing time of the alert function.
  2. B
    Decrease the AWS Lambda function's timeout to 1515 seconds to match the current Amazon SQS visibility timeout configuration.
  3. Increase the Amazon SQS queue's visibility timeout to 180180 seconds to satisfy the recommendation of being at least 6 times the Lambda function's timeout.Cevap
  4. D
    Modify the AWS Lambda function code to initialize a new Amazon SQS client with hardcoded administrator AWS access keys to delete the message immediately upon invocation.

Cevap

Increase the Amazon SQS queue's visibility timeout to 180180 seconds to satisfy the recommendation of being at least 6 times the Lambda function's timeout.
Increasing the Amazon SQS queue's visibility timeout to 180180 seconds matches the AWS recommendation of setting the visibility timeout to at least 6 times the Lambda function's timeout (6×306 \times 30 seconds). This prevents duplicate message processing by ensuring the message is not visible to other consumers while the Lambda function is executing or retrying.

Adım Adım Çözüm

1
Identify the relationship between the Lambda function timeout and SQS visibility timeout.
The Lambda function timeout is set to 3030 seconds, while the SQS visibility timeout is set to 1515 seconds.
If the Lambda function takes longer than 1515 seconds to process a message (and it can take up to 2020 seconds), the message's visibility timeout will expire, making the message visible again in the queue before processing finishes, leading to duplicate processing.
2
Apply AWS best practices for setting visibility timeout when integrating SQS with Lambda.
AWS recommends setting the SQS visibility timeout to at least 6 times the Lambda function's timeout.
This extra buffer prevents duplicate message processing by ensuring the message remains invisible during Lambda function execution retries.
3
Calculate the required SQS visibility timeout.
Multiplying the Lambda timeout of 3030 seconds by 6 yields 180180 seconds.
An SQS visibility timeout of at least 180180 seconds is required to satisfy the best practices configuration.

Anahtar Kavram

Configuring SQS Visibility Timeout for Lambda Event Source Mapping
Bu soruyu puanla