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

Enhancement request: option to run LifespanCycle on Mangum __init__ rather than on each __call__ #342

Open
jrobbins-LiveData opened this issue Feb 16, 2025 · 0 comments

Comments

@jrobbins-LiveData
Copy link

While in some sense "Lambda is stateless", in practice AWS recommends

Initialize SDK clients and database connections outside of the function handler, and cache static assets locally in the /tmp directory. Subsequent invocations processed by the same instance of your function can reuse these resources. This saves cost by reducing function run time.

If I instance Mangum outside of my function handler, it would be great to have the option for my lifespan asynccontextmanager to run once, e.g. at the onset of the first handler call, rather than on every call. This would support use-cases like caching a database connection per AWS recommendation without resorting to workarounds.

This option would allow treating the model of lifespan to cover the actual lifespan of the Lambda function instance, and so, at least to me, seems like a "natural" mapping of the concept of "lifespan".

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

No branches or pull requests

1 participant