Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom runtimes option for titiler and ingestor #66

Merged
merged 6 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
75 changes: 72 additions & 3 deletions lib/ingestor-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
RemovalPolicy,
Stack,
} from "aws-cdk-lib";
import { PythonFunction } from "@aws-cdk/aws-lambda-python-alpha";
import { PythonFunction, PythonFunctionProps } from "@aws-cdk/aws-lambda-python-alpha";
import { Construct } from "constructs";

export class StacIngestor extends Construct {
Expand Down Expand Up @@ -55,6 +55,7 @@ export class StacIngestor extends Construct {
dbVpc: props.vpc,
dbSecurityGroup: props.stacDbSecurityGroup,
subnetSelection: props.subnetSelection,
apiCode: props.apiCode,
});

this.buildApiEndpoint({
Expand All @@ -72,6 +73,7 @@ export class StacIngestor extends Construct {
dbVpc: props.vpc,
dbSecurityGroup: props.stacDbSecurityGroup,
subnetSelection: props.subnetSelection,
ingestorCode: props.ingestorCode,
});

this.registerSsmParameter({
Expand Down Expand Up @@ -108,11 +110,17 @@ export class StacIngestor extends Construct {
dbVpc: ec2.IVpc;
dbSecurityGroup: ec2.ISecurityGroup;
subnetSelection: ec2.SubnetSelection
apiCode?: ApiCode;
}): PythonFunction {

const handler = new PythonFunction(this, "api-handler", {
const apiCode = props.apiCode || {
entry: `${__dirname}/runtime`,
index: "src/handler.py",
handler: "handler",
};

const handler = new PythonFunction(this, "api-handler", {
...apiCode,
runtime: lambda.Runtime.PYTHON_3_9,
timeout: Duration.seconds(30),
environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env },
Expand Down Expand Up @@ -145,10 +153,19 @@ export class StacIngestor extends Construct {
dbVpc: ec2.IVpc;
dbSecurityGroup: ec2.ISecurityGroup;
subnetSelection: ec2.SubnetSelection;
ingestorCode?: IngestorCode;
}): PythonFunction {
const handler = new PythonFunction(this, "stac-ingestor", {



const ingestorCode = props.ingestorCode || {
entry: `${__dirname}/runtime`,
index: "src/ingestor.py",
handler: "handler",
};

const handler = new PythonFunction(this, "stac-ingestor", {
...ingestorCode,
runtime: lambda.Runtime.PYTHON_3_9,
timeout: Duration.seconds(180),
environment: { DB_SECRET_ARN: props.dbSecret.secretArn, ...props.env },
Expand Down Expand Up @@ -290,4 +307,56 @@ export interface StacIngestorProps {
* Custom Domain Name Options for Ingestor API
*/
readonly ingestorDomainNameOptions?: apigateway.DomainNameOptions;

/**
* Custom code for the ingestor api.
*
* @default - default in the runtime folder.
*/
readonly apiCode?: ApiCode;

/**
* Custom code for the ingestor.
*
* @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.
*/
readonly entry: PythonFunctionProps["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.
*/
readonly handler: PythonFunctionProps["handler"];

}

export interface IngestorCode {

/**
* 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`.
*/
readonly index: PythonFunctionProps["index"];

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

}
20 changes: 18 additions & 2 deletions lib/titiler-pgstac-api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ import {
this.titilerPgstacLambdaFunction = new lambda.Function(this, "lambda", {
handler: "handler.handler",
runtime: lambda.Runtime.PYTHON_3_10,
code: lambda.Code.fromDockerBuild(__dirname, {
code: props.titilerApiAsset ?? lambda.Code.fromDockerBuild(__dirname, {
file: "runtime/Dockerfile",
buildArgs: { PYTHON_VERSION: '3.10' },
}),
timeout: Duration.seconds(30),
vpc: props.vpc,
vpcSubnets: props.subnetSelection,
allowPublicSubnet: true,
memorySize: 3008,
memorySize: props.titilerLambdaMemorySize ?? 3008,
logRetention: aws_logs.RetentionDays.ONE_WEEK,
environment: titilerPgstacEnv,
});
emileten marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -118,4 +118,20 @@ import {
* Custom Domain Name Options for Titiler Pgstac API,
*/
readonly titilerPgstacApiDomainName?: IDomainName;

/**
* asset created by a docker build with the titiler pgstac application,
* can be produced with lambda.Code.fromDockerBuild.
*
* If undefined, the default application contained in the runtime folder will be used.
*
* @default - undefined
*/
readonly titilerApiAsset?: lambda.AssetCode;


/**
* amount of memory to allocate to the lambda function.
*/
readonly titilerLambdaMemorySize?: number;
}
Loading