Skip to content

Commit eb48205

Browse files
authored
fix: add vpc, subnet_selection, lambaFunctionOptions props (#151)
adds flexibility to StacItemLoader and StactoolsItemGenerator
1 parent b1de24a commit eb48205

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

lib/stac-item-loader/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
aws_ec2 as ec2,
23
aws_lambda as lambda,
34
aws_sqs as sqs,
45
aws_sns as sns,
@@ -11,6 +12,7 @@ import {
1112
import { Construct } from "constructs";
1213
import { PgStacDatabase } from "../database";
1314
import * as path from "path";
15+
import { CustomLambdaFunctionProps } from "../utils";
1416

1517
/**
1618
* Configuration properties for the StacItemLoader construct.
@@ -41,6 +43,16 @@ export interface StacItemLoaderProps {
4143
*/
4244
readonly pgstacDb: PgStacDatabase;
4345

46+
/**
47+
* VPC into which the lambda should be deployed.
48+
*/
49+
readonly vpc?: ec2.IVpc;
50+
51+
/**
52+
* Subnet into which the lambda should be deployed.
53+
*/
54+
readonly subnetSelection?: ec2.SubnetSelection;
55+
4456
/**
4557
* The lambda runtime to use for the item loading function.
4658
*
@@ -124,6 +136,13 @@ export interface StacItemLoaderProps {
124136
* PGSTAC_SECRET_ARN. Use this for custom configuration or debugging flags.
125137
*/
126138
readonly environment?: { [key: string]: string };
139+
140+
/**
141+
* Can be used to override the default lambda function properties.
142+
*
143+
* @default - defined in the construct.
144+
*/
145+
readonly lambdaFunctionOptions?: CustomLambdaFunctionProps;
127146
}
128147

129148
/**
@@ -375,6 +394,8 @@ export class StacItemLoader extends Construct {
375394
this.lambdaFunction = new lambda.Function(this, "Function", {
376395
runtime: lambdaRuntime,
377396
handler: "stac_item_loader.handler.handler",
397+
vpc: props.vpc,
398+
vpcSubnets: props.subnetSelection,
378399
code: lambda.Code.fromDockerBuild(path.join(__dirname, ".."), {
379400
file: "stac-item-loader/runtime/Dockerfile",
380401
platform: "linux/amd64",
@@ -391,6 +412,8 @@ export class StacItemLoader extends Construct {
391412
PGSTAC_SECRET_ARN: props.pgstacDb.pgstacSecret.secretArn,
392413
...props.environment,
393414
},
415+
// overwrites defaults with user-provided configurable properties
416+
...props.lambdaFunctionOptions,
394417
});
395418

396419
// Grant permissions to read the database secret

lib/stactools-item-generator/index.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
aws_ec2 as ec2,
23
aws_lambda as lambda,
34
aws_sqs as sqs,
45
aws_sns as sns,
@@ -11,6 +12,7 @@ import {
1112
import { Construct } from "constructs";
1213
import { Platform } from "aws-cdk-lib/aws-ecr-assets";
1314
import * as path from "path";
15+
import { CustomLambdaFunctionProps } from "../utils";
1416

1517
/**
1618
* Configuration properties for the StactoolsItemGenerator construct.
@@ -40,6 +42,16 @@ export interface StactoolsItemGeneratorProps {
4042
*/
4143
readonly lambdaRuntime?: lambda.Runtime;
4244

45+
/**
46+
* VPC into which the lambda should be deployed.
47+
*/
48+
readonly vpc?: ec2.IVpc;
49+
50+
/**
51+
* Subnet into which the lambda should be deployed.
52+
*/
53+
readonly subnetSelection?: ec2.SubnetSelection;
54+
4355
/**
4456
* The timeout for the item generation lambda in seconds.
4557
*
@@ -105,6 +117,13 @@ export interface StactoolsItemGeneratorProps {
105117
* processing and database insertion.
106118
*/
107119
readonly itemLoadTopicArn: string;
120+
121+
/**
122+
* Can be used to override the default lambda function properties.
123+
*
124+
* @default - defined in the construct.
125+
*/
126+
readonly lambdaFunctionOptions?: CustomLambdaFunctionProps;
108127
}
109128

110129
/**
@@ -260,7 +279,11 @@ export class StactoolsItemGenerator extends Construct {
260279
*/
261280
public readonly lambdaFunction: lambda.DockerImageFunction;
262281

263-
constructor(scope: Construct, id: string, props: StactoolsItemGeneratorProps) {
282+
constructor(
283+
scope: Construct,
284+
id: string,
285+
props: StactoolsItemGeneratorProps
286+
) {
264287
super(scope, id);
265288

266289
const timeoutSeconds = props.lambdaTimeoutSeconds ?? 120;
@@ -301,13 +324,17 @@ export class StactoolsItemGenerator extends Construct {
301324
},
302325
}),
303326
memorySize: props.memorySize ?? 1024,
327+
vpc: props.vpc,
328+
vpcSubnets: props.subnetSelection,
304329
timeout: Duration.seconds(timeoutSeconds),
305330
logRetention: logs.RetentionDays.ONE_WEEK,
306331
environment: {
307332
ITEM_LOAD_TOPIC_ARN: props.itemLoadTopicArn,
308333
LOG_LEVEL: "INFO",
309334
...props.environment,
310335
},
336+
// overwrites defaults with user-provided configurable properties
337+
...props.lambdaFunctionOptions,
311338
});
312339

313340
// Add SQS event source to the lambda

0 commit comments

Comments
 (0)