Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/bootstrapper/runtime/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM lambci/lambda:build-python3.8
ARG PYTHON_VERSION=3.11

FROM public.ecr.aws/lambda/python:${PYTHON_VERSION}

ARG PGSTAC_VERSION
RUN echo "Using PGSTAC Version ${PGSTAC_VERSION}"

WORKDIR /tmp

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

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

Expand All @@ -15,4 +17,4 @@ RUN rm -rf /asset/asyncio*

# A command must be present avoid the following error on CDK deploy:
# Error response from daemon: No command specified
CMD [ "echo", "ready to go!" ]
CMD [ "echo", "ready to go!" ]
24 changes: 12 additions & 12 deletions lib/ingestor-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class StacIngestor extends Construct {
),
],
});

const handler = this.buildApiLambda({
table: this.table,
env,
Expand Down Expand Up @@ -112,7 +112,7 @@ export class StacIngestor extends Construct {
subnetSelection: ec2.SubnetSelection
apiCode?: ApiCode;
}): PythonFunction {

const apiCode = props.apiCode || {
entry: `${__dirname}/runtime`,
index: "src/handler.py",
Expand All @@ -121,7 +121,7 @@ export class StacIngestor extends Construct {

const handler = new PythonFunction(this, "api-handler", {
...apiCode,
runtime: lambda.Runtime.PYTHON_3_9,
runtime: lambda.Runtime.PYTHON_3_11,
timeout: Duration.seconds(30),
environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env },
vpc: props.dbVpc,
Expand Down Expand Up @@ -166,7 +166,7 @@ export class StacIngestor extends Construct {

const handler = new PythonFunction(this, "stac-ingestor", {
...ingestorCode,
runtime: lambda.Runtime.PYTHON_3_9,
runtime: lambda.Runtime.PYTHON_3_11,
timeout: Duration.seconds(180),
environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env },
vpc: props.dbVpc,
Expand Down Expand Up @@ -311,32 +311,32 @@ export interface StacIngestorProps {
/**
* Custom code for the ingestor api.
*
* @default - default in the runtime folder.
* @default - default in the runtime folder.
*/
readonly apiCode?: ApiCode;

/**
* Custom code for the ingestor.
*
* @default - default in the runtime folder.
* @default - default in the runtime folder.
*/
readonly ingestorCode?: IngestorCode;
}

export interface ApiCode {

/**
* Path to the source of the function or the location for dependencies, for the api lambda.
* Path to the source of the function or the location for dependencies, for the api lambda.
*/
readonly entry: PythonFunctionProps["entry"];

/**
* Path to the index file containing the exported handler, relative to `api_lambda_entry`.
* Path to the index file containing the exported handler, relative to `api_lambda_entry`.
*/
readonly index: PythonFunctionProps["index"];

/**
* The name of the exported handler in the `api_lambda_index` file.
* The name of the exported handler in the `api_lambda_index` file.
*/
readonly handler: PythonFunctionProps["handler"];

Expand All @@ -345,12 +345,12 @@ export interface ApiCode {
export interface IngestorCode {

/**
* Path to the source of the function or the location for dependencies, for the ingestor lambda.
* Path to the source of the function or the location for dependencies, for the ingestor lambda.
*/
readonly entry: PythonFunctionProps["entry"];

/**
* Path to the index file containing the exported handler, relative to `ingestor_lambda_entry`.
* Path to the index file containing the exported handler, relative to `ingestor_lambda_entry`.
*/
readonly index: PythonFunctionProps["index"];

Expand All @@ -359,4 +359,4 @@ export interface IngestorCode {
*/
readonly handler: PythonFunctionProps["handler"];

}
}
4 changes: 2 additions & 2 deletions lib/stac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class PgStacApiLambda extends Construct {
* package has a hash.)
* anyio==3.6.1 --hash=sha256:cb29b9c70620506a9a8f87a309591713446953302d7d995344d0d7c6c0c9a7be
* */
runtime: lambda.Runtime.PYTHON_3_8,
runtime: lambda.Runtime.PYTHON_3_11,
architecture: lambda.Architecture.X86_64,
environment: {
PGSTAC_SECRET_ARN: props.dbSecret.secretArn,
Expand All @@ -58,7 +58,7 @@ export class PgStacApiLambda extends Construct {
this.stacApiLambdaFunction.connections.allowTo(props.db, ec2.Port.tcp(5432));

const stacApi = new HttpApi(this, `${Stack.of(this).stackName}-stac-api`, {
defaultDomainMapping: props.stacApiDomainName ? {
defaultDomainMapping: props.stacApiDomainName ? {
domainName: props.stacApiDomainName
} : undefined,
defaultIntegration: new HttpLambdaIntegration("integration", this.stacApiLambdaFunction),
Expand Down
12 changes: 6 additions & 6 deletions lib/tipg-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {

this.tiPgLambdaFunction = new PythonFunction(this, "tipg-api", {
...apiCode,
runtime: lambda.Runtime.PYTHON_3_10,
runtime: lambda.Runtime.PYTHON_3_11,
architecture: lambda.Architecture.X86_64,
environment: {
PGSTAC_SECRET_ARN: props.dbSecret.secretArn,
Expand All @@ -49,7 +49,7 @@ import {
this.tiPgLambdaFunction.connections.allowTo(props.db, ec2.Port.tcp(5432), "allow connections from tipg");

const tipgApi = new HttpApi(this, `${Stack.of(this).stackName}-tipg-api`, {
defaultDomainMapping: props.tipgApiDomainName ? {
defaultDomainMapping: props.tipgApiDomainName ? {
domainName: props.tipgApiDomainName
} : undefined,
defaultIntegration: new HttpLambdaIntegration("integration", this.tiPgLambdaFunction),
Expand Down Expand Up @@ -97,11 +97,11 @@ import {
* Customized environment variables to send to titiler-pgstac runtime.
*/
readonly apiEnv?: Record<string, string>;

/**
* Custom Domain Name for tipg API. If defined, will create the
* domain name and integrate it with the tipg API.
*
* Custom Domain Name for tipg API. If defined, will create the
* domain name and integrate it with the tipg API.
*
* @default - undefined
*/
readonly tipgApiDomainName?: IDomainName;
Expand Down
42 changes: 21 additions & 21 deletions lib/titiler-pgstac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ import {
import { IDomainName, HttpApi } from "@aws-cdk/aws-apigatewayv2-alpha";
import { HttpLambdaIntegration } from "@aws-cdk/aws-apigatewayv2-integrations-alpha";
import { Construct } from "constructs";


// default settings that can be overridden by the user-provided environment.

// default settings that can be overridden by the user-provided environment.
let defaultTitilerPgstacEnv :{ [key: string]: any } = {
"CPL_VSIL_CURL_ALLOWED_EXTENSIONS": ".tif,.TIF,.tiff",
"GDAL_CACHEMAX": "200",
"GDAL_CACHEMAX": "200",
"GDAL_DISABLE_READDIR_ON_OPEN": "EMPTY_DIR",
"GDAL_INGESTED_BYTES_AT_OPEN": "32768",
"GDAL_HTTP_MERGE_CONSECUTIVE_RANGES": "YES",
"GDAL_HTTP_MULTIPLEX": "YES",
"GDAL_HTTP_VERSION": "2",
"PYTHONWARNINGS": "ignore",
"VSI_CACHE": "TRUE",
"VSI_CACHE_SIZE": "5000000",
"VSI_CACHE_SIZE": "5000000",
"DB_MIN_CONN_SIZE": "1",
"DB_MAX_CONN_SIZE": "1"
}

export class TitilerPgstacApiLambda extends Construct {
readonly url: string;
public titilerPgstacLambdaFunction: lambda.Function;

constructor(scope: Construct, id: string, props: TitilerPgStacApiLambdaProps) {
super(scope, id);

Expand All @@ -45,7 +45,7 @@ import {
const apiEnv = props.apiEnv ? { ...defaultTitilerPgstacEnv, ...props.apiEnv, "PGSTAC_SECRET_ARN": props.dbSecret.secretArn } : defaultTitilerPgstacEnv;

const pythonLambdaOptions: TitilerPgstacPythonLambdaOptions = props.pythonLambdaOptions ?? {
runtime: lambda.Runtime.PYTHON_3_10,
runtime: lambda.Runtime.PYTHON_3_11,
entry: `${__dirname}/runtime`,
index: "src/handler.py",
handler: "handler",
Expand All @@ -62,7 +62,7 @@ import {
logRetention: aws_logs.RetentionDays.ONE_WEEK,
timeout: Duration.seconds(30)
})

// grant access to buckets using addToRolePolicy
if (props.buckets) {
props.buckets.forEach(bucket => {
Expand All @@ -72,63 +72,63 @@ import {
}));
});
}

props.dbSecret.grantRead(this.titilerPgstacLambdaFunction);
this.titilerPgstacLambdaFunction.connections.allowTo(props.db, ec2.Port.tcp(5432), "allow connections from titiler");

const stacApi = new HttpApi(this, `${Stack.of(this).stackName}-titiler-pgstac-api`, {
defaultDomainMapping: props.titilerPgstacApiDomainName ? {
domainName: props.titilerPgstacApiDomainName
defaultDomainMapping: props.titilerPgstacApiDomainName ? {
domainName: props.titilerPgstacApiDomainName
} : undefined,
defaultIntegration: new HttpLambdaIntegration("integration", this.titilerPgstacLambdaFunction),
});

this.url = stacApi.url!;

new CfnOutput(this, "titiler-pgstac-api-output", {
exportName: `${Stack.of(this).stackName}-titiler-pgstac-url`,
value: this.url,
});
}
}

export interface TitilerPgStacApiLambdaProps {

/**
* VPC into which the lambda should be deployed.
*/
readonly vpc: ec2.IVpc;

/**
* RDS Instance with installed pgSTAC.
*/
readonly db: rds.IDatabaseInstance;

/**
* Subnet into which the lambda should be deployed.
*/
readonly subnetSelection: ec2.SubnetSelection;

/**
* Secret containing connection information for pgSTAC database.
*/
readonly dbSecret: secretsmanager.ISecret;

/**
* Customized environment variables to send to titiler-pgstac runtime. These will be merged with `defaultTitilerPgstacEnv`.
* The database secret arn is automatically added to the environment variables at deployment.
* The database secret arn is automatically added to the environment variables at deployment.
/*/
readonly apiEnv?: Record<string, string>;

/**
* list of buckets the lambda will be granted access to.
* list of buckets the lambda will be granted access to.
*/
readonly buckets?: string[];

/**
* Custom Domain Name Options for Titiler Pgstac API,
*
* @default - undefined.
*
* @default - undefined.
*/
readonly titilerPgstacApiDomainName?: IDomainName;

Expand Down
Loading