A developer is configuring a serverless application where an Amazon Simple Queue Service (Amazon SQS) queue triggers an AWS Lambda function to process messages. During integration testing, the developer notices that some messages are being processed multiple times by different Lambda invocations, even though the Lambda function eventually runs successfully. The Lambda function is currently configured with an execution timeout of . Which two actions should the developer take to resolve this issue? (Select two.)
- Increase the visibility timeout of the Amazon SQS queue to at least .Answer
- Ensure the Lambda function's execution timeout is configured to be greater than the maximum time required to process the batch of messages.Answer
- CSet the SQS queue's visibility timeout to a value less than to ensure that failed messages are quickly retried by other invocations.
- DModify the Lambda function's IAM trust policy to grant the `sqs:ReceiveMessage` and `sqs:DeleteMessage` permissions to the SQS queue service principal.
- EConfigure the Lambda function to run inside a private VPC subnet without a NAT Gateway or VPC endpoint to restrict SQS traffic to the internal AWS network.
Answer
To resolve the duplicate processing issue, the developer must increase the SQS visibility timeout to at least 6 times the Lambda function's timeout () and ensure the Lambda function's execution timeout is configured to be greater than the maximum time required to process the batch of messages.
To prevent duplicate processing of SQS messages by Lambda, the SQS queue's visibility timeout must be set to at least 6 times the Lambda function's timeout. With a Lambda timeout, the visibility timeout must be at least (). Additionally, the Lambda execution timeout itself must be configured to be greater than the maximum time needed to process a batch of messages to prevent premature termination.
Step-by-Step Solution
Key Concept
Integrating Amazon SQS with AWS Lambda event source mapping and managing visibility timeout and execution timeout relationships.