My SQS FIFO triggers lambda function. SQS sent 4 messages but lambda invoked twice. Concurrency is "Unreserved account concurrency & 1000". What can go wrong?
Asked
Active
Viewed 539 times
-1
-
3a single function invocation can process more then 1 msg from the queue. – Marcin Mar 23 '22 at 09:01
1 Answers
1
The AWS Lambda function can be invoked with more than one Record in the event
.
For example, in Python you would process the event like this:
def lambda_handler(event, context):
for record in event['Records']:
message = record['body']
print("From SQS: " + message)
The maximum number of messages passed to a Lambda function can be controlled with the Batch Size parameter in the trigger:

John Rotenstein
- 241,921
- 22
- 380
- 470
-
Thanks for the response John. These 4 messages passed into the SQS in 1sec (not as batch, these are stock market order execution messages). – anilraj Mar 23 '22 at 09:52
-
1Yes. And when the messages are passed to AWS Lambda, multiple messages can be passed to a single Lambda function invocation unless you have specifically set the batch size to 1 in the Trigger. – John Rotenstein Mar 23 '22 at 10:29
-
you mean lambda function might received 4 messages but skipped 2 from processing? I added print statement as a first statement in the lambda but nothing printed in the console and also added DLQ but nothing captured. – anilraj Mar 23 '22 at 12:35
-
Did you put `print(event)` at the start of the function? It should print the entire contents of the `event`, showing whether there are multiple records. I have added a screenshot of the Trigger configuration where you can set the maximum batch size. If you set this to `1`, then only a single SQS message will be passed to the Lambda function on each invocation. – John Rotenstein Mar 23 '22 at 21:43
-
You said that "the lambda but nothing printed in the console" -- when an AWS Lambda function is triggered by an Amazon SQS message, there is no "console". Any `print()` statements will be stored in CloudWatch Logs. Make sure that the IAM Role assigned to your Lambda function has been assigned the `AWSLambdaBasicExecutionRole` so that it has permissions to write logs to CloudWatch Logs. See: [AWS Lambda execution role - AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html) – John Rotenstein Mar 23 '22 at 21:50
-
my bad, i am checking in cloudwatch logs. I did not get chance to test today. will check tomorrow and let you know. Heartfelt Thanks to your time and help :) – anilraj Mar 24 '22 at 04:16