Skip to content

Commit 7753187

Browse files
authored
!feat: update versions for pgstac, stac-fastapi-pgstac, titiler-pgstac, and tipg (#128)
* import default app constructs rather than creating lightly customized ones
1 parent e01457f commit 7753187

File tree

18 files changed

+111
-263
lines changed

18 files changed

+111
-263
lines changed

lib/database/bootstrapper_runtime/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}
44
RUN echo "PYTHON_VERSION: ${PYTHON_VERSION}"
55

66
WORKDIR /tmp
7-
8-
RUN pip install httpx psycopg[binary,pool] pypgstac -t /asset
7+
ARG PGSTAC_VERSION
8+
RUN pip install httpx psycopg[binary,pool] pypgstac==${PGSTAC_VERSION} -t /asset
99

1010
COPY bootstrapper_runtime/handler.py /asset/handler.py
1111

lib/database/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { CustomLambdaFunctionProps } from "../utils";
1414
import { PgBouncer } from "./PgBouncer";
1515

1616
const instanceSizes: Record<string, number> = require("./instance-memory.json");
17-
const DEFAULT_PGSTAC_VERSION = "0.8.5";
17+
const DEFAULT_PGSTAC_VERSION = "0.9.5";
1818

1919
let defaultPgSTACCustomOptions: { [key: string]: any } = {
2020
context: "FALSE",
@@ -69,7 +69,7 @@ export class PgStacDatabase extends Construct {
6969
parameterGroup,
7070
...props,
7171
});
72-
72+
const pgstac_version = props.pgstacVersion || DEFAULT_PGSTAC_VERSION;
7373
const handler = new aws_lambda.Function(this, "lambda", {
7474
// defaults
7575
runtime: aws_lambda.Runtime.PYTHON_3_11,
@@ -81,6 +81,7 @@ export class PgStacDatabase extends Construct {
8181
file: "bootstrapper_runtime/Dockerfile",
8282
buildArgs: {
8383
PYTHON_VERSION: "3.11",
84+
PGSTAC_VERSION: pgstac_version,
8485
},
8586
}),
8687
vpc: hasVpc(this.db) ? this.db.vpc : props.vpc,
@@ -131,8 +132,7 @@ export class PgStacDatabase extends Construct {
131132

132133
// if props.lambdaFunctionOptions doesn't have 'code' defined, update pgstac_version (needed for default runtime)
133134
if (!props.bootstrapperLambdaFunctionOptions?.code) {
134-
customResourceProperties["pgstac_version"] =
135-
props.pgstacVersion || DEFAULT_PGSTAC_VERSION;
135+
customResourceProperties["pgstac_version"] = pgstac_version;
136136
}
137137

138138
// add timestamp to properties to ensure the Lambda gets re-executed on each deploy

lib/stac-api/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IDomainName, HttpApi, ParameterMapping, MappingValue} from "@aws-cdk/aw
1212
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
1313
import { Construct } from "constructs";
1414
import { CustomLambdaFunctionProps } from "../utils";
15+
import * as path from 'path';
1516

1617
export class PgStacApiLambda extends Construct {
1718
readonly url: string;
@@ -23,12 +24,12 @@ export class PgStacApiLambda extends Construct {
2324
this.stacApiLambdaFunction = new lambda.Function(this, "lambda", {
2425
// defaults
2526
runtime: lambda.Runtime.PYTHON_3_11,
26-
handler: "src.handler.handler",
27+
handler: "handler.handler",
2728
memorySize: 8192,
2829
logRetention: aws_logs.RetentionDays.ONE_WEEK,
2930
timeout: Duration.seconds(30),
30-
code: lambda.Code.fromDockerBuild(__dirname, {
31-
file: "runtime/Dockerfile",
31+
code: lambda.Code.fromDockerBuild(path.join(__dirname, '..'), {
32+
file: "stac-api/runtime/Dockerfile",
3233
buildArgs: { PYTHON_VERSION: '3.11' },
3334
}),
3435
vpc: props.vpc,

lib/stac-api/runtime/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}
44
WORKDIR /tmp
55
RUN python -m pip install pip -U
66

7-
COPY runtime/requirements.txt requirements.txt
7+
COPY stac-api/runtime/requirements.txt requirements.txt
88
RUN python -m pip install -r requirements.txt "mangum>=0.14,<0.15" -t /asset --no-binary pydantic
99

1010
RUN mkdir -p /asset/src
11-
COPY runtime/src/*.py /asset/src/
11+
COPY stac-api/runtime/src/*.py /asset/
12+
COPY utils/utils.py /asset/
1213

1314
CMD ["echo", "hello world"]

lib/stac-api/runtime/requirements.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
stac-fastapi.api==2.4.8
2-
stac-fastapi.extensions==2.4.8
3-
stac-fastapi.pgstac==2.4.8
4-
stac-fastapi.types==2.4.8
5-
# https://github.com/stac-utils/stac-fastapi/pull/466
6-
pygeoif==0.7
7-
starlette_cramjam
1+
stac-fastapi-pgstac>=5.0,<5.1
2+
starlette-cramjam>=0.4,<0.5

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

Lines changed: 0 additions & 58 deletions
This file was deleted.

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

Lines changed: 0 additions & 97 deletions
This file was deleted.

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,37 @@
66
import os
77

88
from mangum import Mangum
9+
from stac_fastapi.pgstac.app import app
10+
from stac_fastapi.pgstac.config import PostgresSettings
11+
from stac_fastapi.pgstac.db import close_db_connection, connect_to_db
12+
from utils import get_secret_dict
13+
14+
secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
15+
postgres_settings = PostgresSettings(
16+
postgres_host_reader=secret["host"],
17+
postgres_host_writer=secret["host"],
18+
postgres_dbname=secret["dbname"],
19+
postgres_user=secret["username"],
20+
postgres_pass=secret["password"],
21+
postgres_port=int(secret["port"]),
22+
)
23+
24+
25+
@app.on_event("startup")
26+
async def startup_event():
27+
"""Connect to database on startup."""
28+
print("Setting up DB connection...")
29+
await connect_to_db(app, postgres_settings=postgres_settings)
30+
print("DB connection setup.")
31+
32+
33+
@app.on_event("shutdown")
34+
async def shutdown_event():
35+
"""Close database connection."""
36+
print("Closing up DB connection...")
37+
await close_db_connection(app)
38+
print("DB connection closed.")
939

10-
from .app import app
1140

1241
handler = Mangum(app, lifespan="off")
1342

lib/tipg-api/index.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import {
2-
Stack,
3-
aws_ec2 as ec2,
4-
aws_lambda as lambda,
5-
aws_logs as logs,
6-
aws_rds as rds,
7-
aws_secretsmanager as secretsmanager,
8-
CfnOutput,
9-
Duration,
10-
} from "aws-cdk-lib";
11-
import { IDomainName, HttpApi, ParameterMapping, MappingValue} from "@aws-cdk/aws-apigatewayv2-alpha";
12-
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
13-
import { Construct } from "constructs";
14-
import { CustomLambdaFunctionProps } from "../utils";
2+
Stack,
3+
aws_ec2 as ec2,
4+
aws_lambda as lambda,
5+
aws_logs as logs,
6+
aws_rds as rds,
7+
aws_secretsmanager as secretsmanager,
8+
CfnOutput,
9+
Duration,
10+
} from "aws-cdk-lib";
11+
import { IDomainName, HttpApi, ParameterMapping, MappingValue} from "@aws-cdk/aws-apigatewayv2-alpha";
12+
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
13+
import { Construct } from "constructs";
14+
import { CustomLambdaFunctionProps } from "../utils";
15+
import * as path from 'path';
1516

1617
export class TiPgApiLambda extends Construct {
1718
readonly url: string;
@@ -27,9 +28,9 @@ import {
2728
memorySize: 1024,
2829
logRetention: logs.RetentionDays.ONE_WEEK,
2930
timeout: Duration.seconds(30),
30-
code: lambda.Code.fromDockerBuild(__dirname, {
31-
file: "runtime/Dockerfile",
32-
buildArgs: { PYTHON_VERSION: '3.11' },
31+
code: lambda.Code.fromDockerBuild(path.join(__dirname, '..'), {
32+
file: "tipg-api/runtime/Dockerfile",
33+
buildArgs: { PYTHON_VERSION: '3.11' },
3334
}),
3435
vpc: props.vpc,
3536
vpcSubnets: props.subnetSelection,

lib/tipg-api/runtime/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}
44
WORKDIR /tmp
55
RUN python -m pip install pip -U
66

7-
COPY runtime/requirements.txt requirements.txt
7+
COPY tipg-api/runtime/requirements.txt requirements.txt
88
RUN python -m pip install -r requirements.txt "mangum>=0.14,<0.15" -t /asset --no-binary pydantic
99

1010
# Reduce package size and remove useless files
@@ -13,6 +13,7 @@ RUN cd /asset && find . -type d -a -name '__pycache__' -print0 | xargs -0 rm -rf
1313
RUN cd /asset && find . -type f -a -name '*.py' -print0 | xargs -0 rm -f
1414
RUN find /asset -type d -a -name 'tests' -print0 | xargs -0 rm -rf
1515

16-
COPY runtime/src/*.py /asset/
16+
COPY tipg-api/runtime/src/*.py /asset/
17+
COPY utils/utils.py /asset/
1718

1819
CMD ["echo", "hello world"]

lib/tipg-api/runtime/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tipg==0.6.3
1+
tipg>=1.0,<1.1

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
import os
77

88
from mangum import Mangum
9-
from utils import load_pgstac_secret
9+
from utils import get_secret_dict
1010

11-
load_pgstac_secret(os.environ["PGSTAC_SECRET_ARN"]) # required for the below imports
11+
secret = get_secret_dict(secret_arn_env_var="PGSTAC_SECRET_ARN")
12+
os.environ.update(
13+
{
14+
"postgres_host": secret["host"],
15+
"postgres_dbname": secret["dbname"],
16+
"postgres_user": secret["username"],
17+
"postgres_pass": secret["password"],
18+
"postgres_port": str(secret["port"]),
19+
}
20+
)
1221

1322
from tipg.collections import register_collection_catalog # noqa: E402
1423
from tipg.database import connect_to_db # noqa: E402

0 commit comments

Comments
 (0)