Lambda triggering on each SQS message despite batching size of 500 in lambda event source mapping

Viewed 1746

I've set up a system that looks like this: lambda1 -> SQS -> lambda2

Lambda1 will send a number of messages to SQS (all within a few seconds). I've then set up and event source mapping between the SQS queue and lambda2 to have a MaximumBatchingWindowInSeconds of 180 seconds, and a BatchSize of 500. Given this setup, I'd only expect lambda2 to be triggered once (for up to 500 messages sent from lambda1 within 180 seconds). But the observed behavior (based on number of cloudwatch logs of lambda2), seems to be one trigger per message (SQSEvent passed to handler only contains one record). The MaximumBatchingWindowInSeconds of 180 seconds seems to be in effect though. Another detail is that lambda2's timeout is also 180 seconds. Any ideas on what could be happening here?

MyQueue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: MyQueueName
      ReceiveMessageWaitTimeSeconds: 10
      VisibilityTimeout: 180
LambdaFunctionEventSourceMapping:
    Type: AWS::Lambda::EventSourceMapping
    Properties:
      BatchSize: 500
      Enabled: true
      EventSourceArn: !GetAtt MyQueue.Arn
      FunctionName: !GetAtt MyLambdaFunction.Arn
      MaximumBatchingWindowInSeconds: 180

edit:

lambda1 sends messages to SQS using the sdk: sqsClient.sendMessage(sendSQSMessageRequest);

lambda2 receives SQSEvents through the handleRequest function: public Boolean handleRequest(final SQSEvent sqsEvent, final Context context)

1 Answers

As per https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html

Lambda passes all of the records in the batch to the function in a single call, as long as the total size of the events doesn't exceed the payload limit for synchronous invocation (6 MB).

Payload size can be one of the factors here.

Related