This section describes an issue, and a workaround for Fauna client code running in an AWS Lambda function.
When an AWS Lambda function executes, the execution context is maintained for a short period in anticipation of new requests. If no new request is received in that period, the context is frozen, which stores the current state of the execution context.
When a subsequent request comes in, AWS Lambda can choose to thaw the execution context to service the request, instead of starting the function from scratch. Thawed contexts behave (mostly) like they were never frozen. See AWS Lambda Execution Context for details.
The key point is that when an execution context is frozen, the initialization code has already been run. When the execution context is thawed, execution resumes in the Lambda function’s handler code; initialization code is not re-executed.
Fauna driver connection objects maintain at least one internal socket
connection. Socket connections automatically close after a certain
period when no traffic is exchanged. So, if your Lambda function is
frozen for long enough, its internal socket becomes invalid. When an
execution context is thawed later on, your Lambda function could receive
We recommend that you create your client connection object within your handler functions so that you have a fresh connection object for each thawed context. All Fauna connections are light-weight HTTP connections, with HTTP KeepAlive enabled by default, so there is no performance advantage to creating client connection objects outside of your handlers.
Is this article helpful?
Tell Fauna how the article can be improved:
Thank you for your feedback!