-
-
Notifications
You must be signed in to change notification settings - Fork 132
Description
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".