Skip to content

Commit 9d0b226

Browse files
Merge pull request #103 from developmentseed/fixVectorLifespan
fix lifespan config for eoapi.vector and update docs
2 parents 0798309 + c2d13ae commit 9d0b226

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed

infrastructure/DEPLOYMENT.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,54 @@ The example commands here will deploy a CloudFormation stack called `eoAPI-stagi
2626
npm --prefix infrastructure/aws install
2727
```
2828

29-
3. Install CDK and connect to your AWS account. This step is only necessary once per AWS account. The environment variable `CDK_EOAPI_STAGE` determines the name of the stack
29+
3. Update settings
30+
31+
Set environment variable or hard code in `infrastructure/aws/.env` file (e.g `CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1`).
32+
33+
**Important**:
34+
35+
- `CDK_EOAPI_DB_PGSTAC_VERSION` is a required env (see https://github.com/stac-utils/pgstac/tags for the latest version)
36+
37+
- You can choose which functions to deploy by setting `CDK_EOAPI_FUNCTIONS` env (e.g `CDK_EOAPI_FUNCTIONS='["stac","raster","vector"]'`)
38+
39+
40+
4. Install CDK and connect to your AWS account. This step is only necessary once per AWS account. The environment variable `CDK_EOAPI_STAGE` determines the name of the stack
3041
(e.g. eoAPI-staging or eoAPI-production)
3142
```bash
3243
# Deploy the CDK toolkit stack into an AWS environment.
33-
CDK_EOAPI_STAGE=staging CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 npm --prefix infrastructure/aws run cdk -- bootstrap
44+
CDK_EOAPI_STAGE=staging \
45+
CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 \
46+
npm --prefix infrastructure/aws run cdk -- bootstrap
3447
3548
# or to a specific region
36-
AWS_DEFAULT_REGION=us-west-2 AWS_REGION=us-west-2 CDK_EOAPI_STAGE=staging CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 npm --prefix infrastructure/aws run cdk -- bootstrap
49+
AWS_DEFAULT_REGION=us-west-2 \
50+
AWS_REGION=us-west-2 \
51+
CDK_EOAPI_STAGE=staging \
52+
CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 \
53+
npm --prefix infrastructure/aws run cdk -- bootstrap
3754
```
3855

39-
4. Update settings
40-
41-
Set environment variable or hard code in `infrastructure/aws/.env` file (e.g `CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1`).
42-
43-
**Important**:
44-
- `CDK_EOAPI_DB_PGSTAC_VERSION` is a required env
45-
- You can choose which functions to deploy by setting `CDK_EOAPI_FUNCTIONS` env (e.g `CDK_EOAPI_FUNCTIONS='["stac","raster","vector"]'`)
46-
4756
5. Pre-Generate CFN template
4857

4958
```bash
50-
CDK_EOAPI_STAGE=staging CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 npm --prefix infrastructure/aws run cdk -- synth # Synthesizes and prints the CloudFormation template for this stack
59+
CDK_EOAPI_STAGE=staging \
60+
CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 \
61+
npm --prefix infrastructure/aws run cdk -- synth # Synthesizes and prints the CloudFormation template for this stack
5162
```
5263

5364
6. Deploy
5465

5566
```bash
56-
CDK_EOAPI_STAGE=staging CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 npm --prefix infrastructure/aws run cdk -- deploy eoAPI-${CDK_EOAPI_STAGE}
67+
CDK_EOAPI_STAGE=staging \
68+
CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 \
69+
npm --prefix infrastructure/aws run cdk -- deploy eoAPI-staging
5770
5871
# Deploy in specific region
59-
AWS_DEFAULT_REGION=eu-central-1 AWS_REGION=eu-central-1 CDK_EOAPI_STAGE=staging CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 npm --prefix infrastructure/aws run cdk -- deploy eoapi-${CDK_EOAPI_STAGE} --profile {my-aws-profile}
72+
AWS_DEFAULT_REGION=eu-central-1 \
73+
AWS_REGION=eu-central-1 \
74+
CDK_EOAPI_STAGE=staging \
75+
CDK_EOAPI_DB_PGSTAC_VERSION=0.7.1 \
76+
npm --prefix infrastructure/aws run cdk -- deploy eoapi-staging --profile {my-aws-profile}
6077
```
6178

6279
If you get an error saying that the max VPC's has been reached, this means that you have hit the limit for the amount of VPCs per unique AWS account and region combination. You can change the AWS region to a region that has less VPCs and deploy again to fix this.

infrastructure/aws/cdk/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class eoVectorSettings(pydantic.BaseSettings):
110110
env: Dict = {}
111111

112112
timeout: int = 10
113-
memory: int = 256
113+
memory: int = 512
114114

115115
class Config:
116116
"""model config"""

infrastructure/aws/handlers/vector_handler.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,46 @@
66

77
from eoapi.vector.app import app
88
from mangum import Mangum
9+
from tipg.db import connect_to_db, register_collection_catalog
10+
from tipg.settings import PostgresSettings
911

1012
logging.getLogger("mangum.lifespan").setLevel(logging.ERROR)
1113
logging.getLogger("mangum.http").setLevel(logging.ERROR)
1214

15+
postgres_settings = PostgresSettings()
16+
17+
try:
18+
from importlib.resources import files as resources_files # type: ignore
19+
except ImportError:
20+
# Try backported to PY<39 `importlib_resources`.
21+
from importlib_resources import files as resources_files # type: ignore
22+
23+
24+
CUSTOM_SQL_DIRECTORY = resources_files("eoapi.vector") / "sql"
25+
sql_files = list(CUSTOM_SQL_DIRECTORY.glob("*.sql")) # type: ignore
26+
27+
28+
@app.on_event("startup")
29+
async def startup_event() -> None:
30+
"""Connect to database on startup."""
31+
await connect_to_db(
32+
app,
33+
settings=postgres_settings,
34+
# We enable both pgstac and public schemas (pgstac will be used by custom functions)
35+
schemas=["pgstac", "public"],
36+
user_sql_files=sql_files,
37+
)
38+
await register_collection_catalog(
39+
app,
40+
# For the Tables' Catalog we only use the `public` schema
41+
schemas=["public"],
42+
# We exclude public functions
43+
exclude_function_schemas=["public"],
44+
# We allow non-spatial tables
45+
spatial=False,
46+
)
47+
48+
1349
handler = Mangum(app, lifespan="off")
1450

1551
if "AWS_EXECUTION_ENV" in os.environ:

0 commit comments

Comments
 (0)