skip to Main Content

I have a API Gateway integrated with lambda. When I hit rest API, I notice the logs sometimes goes to existing log stream of lambda and sometimes it creates separate log streams.
SO how aws decides when to create new log stream?
My assumption is for each API request, a separate lambda container will be launched to execute lambda function,hence the logs will also go to new log stream. But this is not the case.

2

Answers


  1. Occasionally lambda may reuse the same container if requests are coming in short span and in such cases, it is possible to have logs in same log stream.

    Login or Signup to reply.
  2. TL;DR, when the lambda function reuses the execution environment, logs go to an existing log stream. Cold start always creates a new execution environment and logs will go to a new log stream.

    Each instance of a Lambda function has a dedicated log stream. If a function scales up, each concurrent instance has its own log stream. Each time an execution environment is reaped and a new environment is created in response to an invocation, this generates a new log stream.

    Ref: https://docs.aws.amazon.com/lambda/latest/operatorguide/log-structure.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search