Guna Sambandhan
Guna Sambandhan

Reputation: 1

SQS triggering lambda in Serverless has latency

I have a use case below

  1. StepFunction -> Lambda -> EventBridge to SQS triggering lambda

When the message receives to Eventbridge it will then publish to SQS and SQS will trigger the lambda. What I have noticed here is every time some message is pushed it takes almost 21 Sec to reach the final lambda.

Configuration of SQS:

Lambda is inside VPC

When I did my analysis, all the bridges is happening in instant but SQS triggering Lambda takes 21 Sec.

All the Blogs am referring to say, it will happen in instant but for me no luck.

Am not sure if my configuration is wrong. Any help is more valuable to me.

Thanks, Guna

Upvotes: 0

Views: 2062

Answers (2)

dansoton
dansoton

Reputation: 411

Expanding on Guna's own answer, we had the same problem, and found that the reason was a documented SQS limitation because we had a batchSize configured of 100 and a maximumBatchingWindow of 1.

AWS states:

If you're using a batch window and your SQS queue contains very low traffic, Lambda might wait for up to 20 seconds before invoking your function. This is true even if you set a batch window lower than 20 seconds.

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

Once we removed both the batchSize and maximumBatchingWindow configuration settings, the SQS-Lambda invocation latency dramatically decreased.

Upvotes: 3

Guna Sambandhan
Guna Sambandhan

Reputation: 1

After further investigation, have noticed that SQS trigger lambda settings in serverless configured for maximumBatchingWindow to specify the maximum amount of time in seconds to gather records before invoking the function. Which is not required when batch size is 1.

Upvotes: 0

Related Questions