Tips and tricks for logging and monitoring AWS Lambda functions
Yan Cui

Great article. Learning a lot and trying to apply it to my project.

Some questions:

Since you’re storing CONTEXT outside of the handler, can that be possibly mutated by concurrent invocations on the same container?

Say for example,

  1. Invocation A arrives (sets the global CONTEXT).
  2. Invocation B arrives before Invocation A finishes (this resets the global CONTEXT for itself).
  3. Invocation B finishes and returns (uses the global CONTEXT).
  4. Invocation A finishes and returns (uses the global CONTEXT but by this time, the state of CONTEXT is for Invocation B).

Am I misunderstanding something?