I've observed an abnormal (well, in my POV) feature, where when I setup SQS to trigger a Lambda, when new messages arrive, lambdas get triggered with more than 1 record/message inside its event body.
Full setup is S3 (PutObjectEvent) -> SNS topic -> SQS -> Lambda.
The abnormal behaviour is that for example, let's say I put 15 objects inside S3, which then forwards an event to SNS per each object, which then I can observe, SQS gets populated with 15 messages. However, when Lambdas start triggering, out of those 15 messages, only 11 Lambdas trigger, some of them containing more than 1 record/message inside its event body.
I've scoured the AWS documentation, but haven't found a concrete answer. Please note, these Lambdas do NOT poll SQS or fail or keep retrying. They execute perfectly fine, its just that inspected event body shows more than 1 record inside of it.
You should not configure multiple Lambda functions as triggers for a single SQS queue. This is because the message in SQS will be delivered to any one consumer and while this message is being processed by that consumer, it would not be visible to others.
By default, Lambda batches up to 10 messages in a queue to process them during a single Lambda execution. You can increase this number up to 10,000 messages, or up to 6 MB of messages in a single batch for standard SQS queues.
Your function can have multiple triggers. Each trigger acts as a client invoking your function independently. Each event that Lambda passes to your function has data from only one client or trigger.
Simply put, SQS triggers: Trigger a Lambda function when on or when messages have been placed in the queue. Leverage existing retry logic and dead letter queues. If the Lambda function does not return success, the message will not be deleted from the queue and will reappear after the visibility timeout has expired.
Look at the sample event data for an SQS Lambda message here. The message is an array of records, which directly implies that there may be more than one SQS record in the message.
The documentation on SQS Lambda integration also clearly states that the Batch Size
setting controls how many records a Lambda function may receive from SQS in a single call, with the default being 10
. If you only want your Lambda functions to receive one message at a time you need to modify the Batch Size
setting to be 1
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With