Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse sequelize instance across lambda invocations to improve performance #386

Open
prestonlimlianjie opened this issue Apr 14, 2021 · 0 comments
Assignees

Comments

@prestonlimlianjie
Copy link
Contributor

In order to fix a sporadic Sequelize connection error bug, we made a quick fix that re-initializes a Sequelize instance with each lambda invocation.

However, we found this new Sequelize documentation PR (still under review) that had recommendations on lambda best practices. A great recommendation is to:

  • create a global sequelize variable (during the lambda Init phase, i.e. outside the handler)
  • during the lambda Invoke phase (within the handler), restart connection pool using sequelize.connectionManager.initPools() and close the connections at the end of the phase using sequelize.connectionManager.close()

Refer to https://github.com/sequelize/sequelize/blob/114c10eb09353cd32a630e42454a5d587ab0aed3/docs/manual/other-topics/aws-lambda.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant