From e18ee272cc40790e336895887ec023210a621b86 Mon Sep 17 00:00:00 2001 From: ividito Date: Fri, 13 Jan 2023 13:30:40 -0400 Subject: [PATCH 1/2] 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 From 263f36075066af93e10f5f6e2ccb0999937b1a5c Mon Sep 17 00:00:00 2001 From: ividito Date: Wed, 18 Jan 2023 18:49:06 -0400 Subject: [PATCH 2/2] lint --- raster_api/runtime/handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raster_api/runtime/handler.py b/raster_api/runtime/handler.py index a02c5ebc..f343d7e1 100644 --- a/raster_api/runtime/handler.py +++ b/raster_api/runtime/handler.py @@ -1,8 +1,8 @@ """AWS Lambda handler.""" +import asyncio import logging import os -import asyncio from mangum import Mangum from src.app import app