# Reducing AWS Lambda Triggered by SQS Latency
There are a few configuration options that can help reduce latency when using an Amazon SQS queue as a trigger for an AWS Lambda function:
- Increase the batch size – The default batch size is 10 messages. Increasing the batch size can reduce the number of Lambda invocations, which in turn reduces latency. You can configure a batch size of up to 10,000 messages for standard queues and 10 messages for FIFO queues.
--batch-size 100
- Increase the batch window – The default batch window is 0 seconds. Increasing the batch window allows Lambda to collect more messages before invoking your function. This can reduce the number of invocations and latency. You can configure a batch window of up to 20 seconds.
--maximum-batching-window-in-seconds 20
- Use long polling – Configure long polling on the SQS queue to reduce empty receives. Lambda will wait up to 20 seconds for a message before timing out. This avoids unnecessary latency from empty receives.
- Increase the queue’s visibility timeout – The visibility timeout should be at least 6 times your function’s timeout plus the batch window. This gives Lambda enough time to process batches and retry on errors.
- Reduce the function’s timeout – A shorter timeout can help reduce latency for each invocation. However, you’ll need to balance this with having enough time to process large batches.
- Configure maximum concurrency – Setting a maximum concurrency limit can help limit the number of concurrent Lambda invocations from an SQS trigger, which may reduce latency.
- Enable partial batch responses – Partial responses allow your function to report specific failures in a batch. This can avoid reprocessing the entire batch and reduce latency.
Hope this helps! Let me know if you have any other questions. I tried to cover the main configuration options that can impact latency when using SQS as a Lambda trigger.
Leave a Comment