Lambda - SQS Event: Batch Size, number of container spawning and termination

488 Views Asked by At

Here is my Lambda function:

LambdaFunction:
  Type: AWS::Serverless::Function
  Properties:
    Description: Lambda Function that is spawned via an SQSEvent
    FunctionName: LambdaFunctionName
    Handler: 'com.amazon.krakenscreenruleengineservicelambda.handler.RulesSubscriptionConsumerHandler::handleRequest'
    Runtime: java8
    Events:
      SubscriptionEvent:
        Type: SQS
        Properties:
          Queue:
            Fn::GetAtt: [SubscriptionQueue, Arn]
          BatchSize: 1
    Timeout: 890
    MemorySize: 1024

I've set BatchSize as 1.

1 assumption I am making is that, a single Lambda container spawning is determined by it's specific START and END requestId. If there are 5 such START and END requestId, that means 5 unique containers were spawned.

Now does this mean that within a START and END requestId, exactly 1 message is processed and for the next message a new container is spawned with a new START and END requestId EVEN if the previous container had the Memory and Time to execute more requests?

1

There are 1 best solutions below

0
On BEST ANSWER

Since you have specified batch size of 1, then the request will include a single SQS message. So "between START and END requestId" would be the log for a single message being processed by Lambda.

However, the same container could be called again with another request, after it has finished. Containers in AWS Lambda can be reused. They are not used for more than one request at a time, but they can be used for many sequential requests.

The time limit on an AWS Lambda function is the time it takes to process a single request. So if the container is reused the time limit starts over with each request.

A single Lambda container could run for hours/days/months, etc., if it is seeing heavy utilization, or if you have provisioned concurrency. It just has a maximum of 15 minutes (or less depending on the configuration) to process a single request.


This is officially documented here, under the "Lambda execution environment lifecycle" section.