From 34f3091f09f6dda1537d0d629b8ea04d89ead0ca Mon Sep 17 00:00:00 2001 From: ividito Date: Fri, 13 Jan 2023 13:30:40 -0400 Subject: [PATCH] Fix mangum db connection pool --- raster_api/runtime/handler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/raster_api/runtime/handler.py b/raster_api/runtime/handler.py index 5de94a8f..a02c5ebc 100644 --- a/raster_api/runtime/handler.py +++ b/raster_api/runtime/handler.py @@ -1,6 +1,8 @@ """AWS Lambda handler.""" import logging +import os +import asyncio from mangum import Mangum from src.app import app @@ -10,7 +12,11 @@ logging.getLogger("mangum.http").setLevel(logging.ERROR) -handler = Mangum(app, lifespan="auto") +handler = Mangum(app, lifespan="off") + +if "AWS_EXECUTION_ENV" in os.environ: + loop = asyncio.get_event_loop() + loop.run_until_complete(app.router.startup()) # Add tracing handler.__name__ = "handler" # tracer requires __name__ to be set