diff --git a/stack/app.py b/stack/app.py index 9b3e793..2a6f1b4 100644 --- a/stack/app.py +++ b/stack/app.py @@ -187,6 +187,10 @@ def __init__( ).to_string(), } + env = {} + env["DB_MIN_CONN_SIZE"] = "1" + env["DB_MAX_CONN_SIZE"] = "1" + api_function = aws_lambda.Function( self, f"{id}-vector-lambda", @@ -201,6 +205,7 @@ def __init__( handler="handler.handler", memory_size=api_settings.memory, timeout=core.Duration.seconds(api_settings.timeout), + environment=env, log_retention=logs.RetentionDays.ONE_WEEK, ) for k, v in db_secrets.items(): diff --git a/stack/app/handler.py b/stack/app/handler.py index 9a2112f..49b67db 100644 --- a/stack/app/handler.py +++ b/stack/app/handler.py @@ -1,7 +1,9 @@ +import os +import asyncio + from tifeatures.db import close_db_connection, connect_to_db, register_table_catalog -from tifeatures.factory import Endpoints -from timvt.factory import VectorTilerFactory +from tifeatures.factory import Endpoints as FeaturesEndpoints from fastapi import FastAPI from starlette_cramjam.middleware import CompressionMiddleware @@ -14,8 +16,8 @@ ) # Register endpoints. -endpoints = Endpoints() -app.include_router(endpoints.router, tags=["Features"]) +endpoints = FeaturesEndpoints() +app.include_router(endpoints.router, tags=["OGC Features"]) # By default the VectorTilerFactory will only create tiles/ and tilejson.json endpoints # mvt_endpoints = VectorTilerFactory() @@ -39,4 +41,8 @@ async def shutdown_event() -> None: await close_db_connection(app) -handler = Mangum(app) +handler = Mangum(app, lifespan="off") + +if "AWS_EXECUTION_ENV" in os.environ: + loop = asyncio.get_event_loop() + loop.run_until_complete(app.router.startup()) diff --git a/stack/app/requirements.txt b/stack/app/requirements.txt index ec88710..f424c69 100644 --- a/stack/app/requirements.txt +++ b/stack/app/requirements.txt @@ -1,4 +1,4 @@ -timvt @ git+https://github.com/developmentseed/timvt -tifeatures @ git+https://github.com/developmentseed/tifeatures +timvt==0.8.0a2 +tifeatures==0.1.0a2 mangum>=0.10.0