Skip to content

Commit

Permalink
fix a couple bugs found in the first changes
Browse files Browse the repository at this point in the history
  • Loading branch information
emileten committed Oct 10, 2023
1 parent eb20644 commit a79fd3c
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
22 changes: 22 additions & 0 deletions lib/bootstrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
import { Construct } from "constructs";
import { CustomLambdaFunctionOptions } from "../utils";

const DEFAULT_PGSTAC_VERSION = "0.6.13";

function hasVpc(
instance: aws_rds.DatabaseInstance | aws_rds.IDatabaseInstance
): instance is aws_rds.DatabaseInstance {
Expand All @@ -27,6 +29,15 @@ export class BootstrapPgStac extends Construct {
constructor(scope: Construct, id: string, props: BootstrapPgStacProps) {
super(scope, id);

// if `lambdaAssetCode` is provided, `pgstacVersion` must be provided, otherwise throw an error
if (props.lambdaAssetCode && !props.pgstacVersion) {
throw new Error(
"If `lambdaAssetCode` is provided, `pgstacVersion` must be provided as well."
);
}

const pgstacVersion = props.pgstacVersion ?? DEFAULT_PGSTAC_VERSION;

const handler = new aws_lambda.Function(this, "lambda", {
...props.lambdaFunctionOptions ?? {
runtime: aws_lambda.Runtime.PYTHON_3_8,
Expand All @@ -37,6 +48,7 @@ export class BootstrapPgStac extends Construct {
},
code: props.lambdaAssetCode ?? aws_lambda.Code.fromDockerBuild(__dirname, {
file: "runtime/Dockerfile",
buildArgs: {PGSTAC_VERSION: pgstacVersion, PYTHON_VERSION: "3.8"}
}),
vpc: hasVpc(props.database) ? props.database.vpc : props.vpc,
});
Expand Down Expand Up @@ -75,6 +87,7 @@ export class BootstrapPgStac extends Construct {
new CustomResource(this, "bootstrapper", {
serviceToken: handler.functionArn,
properties: {
pgstac_version: pgstacVersion,
conn_secret_arn: props.dbSecret.secretArn,
new_user_secret_arn: this.secret.secretArn,
},
Expand Down Expand Up @@ -142,4 +155,13 @@ export interface BootstrapPgStacProps {
* @default default runtime defined in this repository
*/
readonly lambdaAssetCode?: aws_lambda.AssetCode;

/**
* pgSTAC database version to be installed. If a custom `lambdaAssetCode`
* is provided, must be provided and match the version of pgSTAC installed
* in the lambda function.
*
* @default 0.6.13
*/
readonly pgstacVersion?: string;
}
9 changes: 7 additions & 2 deletions lib/bootstrapper/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
FROM lambci/lambda:build-python3.8
ARG PYTHON_VERSION
FROM lambci/lambda:build-python${PYTHON_VERSION}

ARG PGSTAC_VERSION
RUN echo "PGSTAC_VERSION: ${PGSTAC_VERSION}"
RUN echo "PYTHON_VERSION: ${PYTHON_VERSION}"

WORKDIR /tmp

RUN pip install httpx psycopg[binary,pool] pypgstac==0.6.13 -t /asset
RUN pip install httpx psycopg[binary,pool] pypgstac==${PGSTAC_VERSION} -t /asset

COPY runtime/handler.py /asset/handler.py

Expand Down
6 changes: 5 additions & 1 deletion lib/ingestor-api/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
FROM public.ecr.aws/lambda/python:3.10
ARG PYTHON_VERSION
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION}

WORKDIR /tmp

RUN yum install -y git

RUN python -m pip install pip -U

COPY runtime/requirements.txt requirements.txt
Expand Down
4 changes: 2 additions & 2 deletions lib/stac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ export class PgStacApiLambda extends Construct {

this.stacApiLambdaFunction = new lambda.Function(this, "lambda", {
...props.lambdaFunctionOptions ?? {
runtime: lambda.Runtime.PYTHON_3_8,
runtime: lambda.Runtime.PYTHON_3_9,
handler: "handler.handler",
memorySize: 8192,
logRetention: aws_logs.RetentionDays.ONE_WEEK,
timeout: Duration.seconds(30)
},
code: props.lambdaAssetCode ?? lambda.Code.fromDockerBuild(__dirname, {
file: "runtime/Dockerfile",
buildArgs: { PYTHON_VERSION: '3.8' },
buildArgs: { PYTHON_VERSION: '3.9' },
}),
vpc: props.vpc,
vpcSubnets: props.subnetSelection,
Expand Down
3 changes: 2 additions & 1 deletion lib/stac-api/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM public.ecr.aws/lambda/python:3.10
ARG PYTHON_VERSION
FROM public.ecr.aws/lambda/python:${PYTHON_VERSION}

WORKDIR /tmp
RUN python -m pip install pip -U
Expand Down
6 changes: 3 additions & 3 deletions lib/tipg-api/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:3.10
ARG PYTHON_VERSION
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}

WORKDIR /tmp
RUN python -m pip install pip -U

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

# Reduce package size and remove useless files
RUN cd /asset && find . -type f -name '*.pyc' | while read f; do n=$(echo $f | sed 's/__pycache__\///' | sed 's/.cpython-[0-9]*//'); cp $f $n; done;
Expand Down
2 changes: 0 additions & 2 deletions lib/tipg-api/runtime/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion lib/tipg-api/runtime/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio
import os
from mangum import Mangum
from src.utils import load_pgstac_secret
from utils import load_pgstac_secret

load_pgstac_secret(os.environ["PGSTAC_SECRET_ARN"]) # required for the below imports

Expand Down
1 change: 1 addition & 0 deletions lib/titiler-pgstac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { CustomLambdaFunctionOptions } from "../utils";
},
code: props.lambdaAssetCode ?? lambda.Code.fromDockerBuild(__dirname, {
file: "runtime/Dockerfile",
buildArgs: { PYTHON_VERSION: '3.10' }
}),
vpc: props.vpc,
vpcSubnets: props.subnetSelection,
Expand Down
3 changes: 2 additions & 1 deletion lib/titiler-pgstac-api/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:3.10
ARG PYTHON_VERSION
FROM --platform=linux/amd64 public.ecr.aws/lambda/python:${PYTHON_VERSION}

WORKDIR /tmp
RUN python -m pip install pip -U
Expand Down
2 changes: 1 addition & 1 deletion lib/titiler-pgstac-api/runtime/src/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import asyncio
import os
from mangum import Mangum
from src.utils import get_secret_dict
from utils import get_secret_dict

pgstac_secret_arn = os.environ["PGSTAC_SECRET_ARN"]

Expand Down

0 comments on commit a79fd3c

Please sign in to comment.