Skip to content

Commit

Permalink
create pool only once and update timvt/tifeatures version (#14)
Browse files Browse the repository at this point in the history
* create pool only once and update timvt/tifeatures version

* Update stack/app/handler.py

Co-authored-by: Jonas <[email protected]>

Co-authored-by: Jonas <[email protected]>
  • Loading branch information
vincentsarago and j08lue authored Dec 15, 2022
1 parent d709ea2 commit c7fd1cf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions stack/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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():
Expand Down
16 changes: 11 additions & 5 deletions stack/app/handler.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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()
Expand All @@ -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())
4 changes: 2 additions & 2 deletions stack/app/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c7fd1cf

Please sign in to comment.