AWS Lambda connections
This section describes an issue, and a workaround for FaunaDB 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.
FaunaDB 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 FaunaDB 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.
Was this article helpful?
We're sorry to hear that.
Tell us how we can improve! firstname.lastname@example.org
Thank you for your feedback!