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.
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
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.
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.
Ref: https://docs.aws.amazon.com/lambda/latest/operatorguide/log-structure.html