diff --git a/raster_api/runtime/handler.py b/raster_api/runtime/handler.py index 5de94a8f..f343d7e1 100644 --- a/raster_api/runtime/handler.py +++ b/raster_api/runtime/handler.py @@ -1,6 +1,8 @@ """AWS Lambda handler.""" +import asyncio import logging +import os 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