Are there issues with accessing data in APIGatewayRestResolver and lambda concurrency #1280
-
In the examples, APIGatewayRestResolver is a global object.
With concurrent lambda executions, this APIGatewayRestResolver instance would be shared by all the concurrent lambdas. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hey @mcsloe - it's safe and allow me to clarify the Lambda concurrency model[1] for you. A Lambda execution environment (container) can only process one request at a time. If a second request comes while the first hasn't completed yet, you now have a concurrency of 2. This means you'll have two completely isolated memory shared space, process map, and disk. When you try to access a request through the global object, you'll always get the request in read-only mode that belongs to that Lambda container handling that request - never shared. What Lambda optimises for is to ensure an idle container doesn't get immediately thrown away - it may take a few minutes or seconds. This allows Lambda to reuse an existing container to handle a new incoming request. Even in this scenario, your app.resolve(event, context) call will hydrate the global object with the new event, thus exposing an updated request details within your functions. Hopefully that clarifies - let us know if you need more details. [1] https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html |
Beta Was this translation helpful? Give feedback.
Hey @mcsloe - it's safe and allow me to clarify the Lambda concurrency model[1] for you.
A Lambda execution environment (container) can only process one request at a time. If a second request comes while the first hasn't completed yet, you now have a concurrency of 2.
This means you'll have two completely isolated memory shared space, process map, and disk.
When you try to access a request through the global object, you'll always get the request in read-only mode that belongs to that Lambda container handling that request - never shared.
What Lambda optimises for is to ensure an idle container doesn't get immediately thrown away - it may take a few minutes or seconds. This allows Lambda t…