Skip to content

Commit 9ea2c18

Browse files
feat!: update titiler version and fix lifespan (#61)
1 parent 402c784 commit 9ea2c18

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

lib/stac-api/runtime/src/handler.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
Handler for AWS Lambda.
33
"""
44

5+
import asyncio
6+
import os
57
from mangum import Mangum
68

79
from .app import app
810

9-
handler = Mangum(app)
11+
handler = Mangum(app, lifespan="off")
12+
13+
14+
if "AWS_EXECUTION_ENV" in os.environ:
15+
loop = asyncio.get_event_loop()
16+
loop.run_until_complete(app.router.startup())
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
titiler.pgstac==0.3.3
1+
titiler.pgstac==0.5.1
22
boto3>=1.26.139
3-
psycopg[binary, pool]
3+
psycopg[binary, pool]

lib/titiler-pgstac-api/runtime/src/handler.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
Handler for AWS Lambda.
33
"""
44

5+
import asyncio
56
import os
67
from mangum import Mangum
78
from utils import get_secret_dict
89
from titiler.pgstac.main import app
10+
from titiler.pgstac.db import connect_to_db
911

1012
pgstac_secret_arn = os.environ["PGSTAC_SECRET_ARN"]
1113

@@ -20,4 +22,16 @@
2022
}
2123
)
2224

23-
handler = Mangum(app)
25+
26+
@app.on_event("startup")
27+
async def startup_event() -> None:
28+
"""Connect to database on startup."""
29+
await connect_to_db(app)
30+
31+
32+
handler = Mangum(app, lifespan="off")
33+
34+
35+
if "AWS_EXECUTION_ENV" in os.environ:
36+
loop = asyncio.get_event_loop()
37+
loop.run_until_complete(app.router.startup())

0 commit comments

Comments
 (0)