@@ -13,7 +13,7 @@ import {
1313 Stack ,
1414} from "aws-cdk-lib" ;
1515import { Construct } from "constructs" ;
16- import { CustomLambdaFunctionProps } from "../utils" ;
16+ import { CustomLambdaFunctionProps , DEFAULT_PGSTAC_VERSION } from "../utils" ;
1717
1818export class StacIngestor extends Construct {
1919 table : dynamodb . Table ;
@@ -39,10 +39,10 @@ export class StacIngestor extends Construct {
3939 assumedBy : new iam . ServicePrincipal ( "lambda.amazonaws.com" ) ,
4040 managedPolicies : [
4141 iam . ManagedPolicy . fromAwsManagedPolicyName (
42- "service-role/AWSLambdaBasicExecutionRole" ,
42+ "service-role/AWSLambdaBasicExecutionRole"
4343 ) ,
4444 iam . ManagedPolicy . fromAwsManagedPolicyName (
45- "service-role/AWSLambdaVPCAccessExecutionRole" ,
45+ "service-role/AWSLambdaVPCAccessExecutionRole"
4646 ) ,
4747 ] ,
4848 } ) ;
@@ -57,6 +57,7 @@ export class StacIngestor extends Construct {
5757 dbSecurityGroup : props . stacDbSecurityGroup ,
5858 subnetSelection : props . subnetSelection ,
5959 lambdaFunctionOptions : props . apiLambdaFunctionOptions ,
60+ pgstacVersion : props . pgstacVersion ,
6061 } ) ;
6162
6263 this . buildApiEndpoint ( {
@@ -74,7 +75,8 @@ export class StacIngestor extends Construct {
7475 dbVpc : props . vpc ,
7576 dbSecurityGroup : props . stacDbSecurityGroup ,
7677 subnetSelection : props . subnetSelection ,
77- lambdaFunctionOptions : props . ingestorLambdaFunctionOptions
78+ lambdaFunctionOptions : props . ingestorLambdaFunctionOptions ,
79+ pgstacVersion : props . pgstacVersion ,
7880 } ) ;
7981
8082 this . registerSsmParameter ( {
@@ -110,20 +112,23 @@ export class StacIngestor extends Construct {
110112 dbSecret : secretsmanager . ISecret ;
111113 dbVpc : undefined | ec2 . IVpc ;
112114 dbSecurityGroup : ec2 . ISecurityGroup ;
113- subnetSelection : undefined | ec2 . SubnetSelection
115+ subnetSelection : undefined | ec2 . SubnetSelection ;
114116 lambdaFunctionOptions ?: CustomLambdaFunctionProps ;
117+ pgstacVersion ?: string ;
115118 } ) : lambda . Function {
116-
117119 const handler = new lambda . Function ( this , "api-handler" , {
118120 // defaults
119121 runtime : lambda . Runtime . PYTHON_3_11 ,
120122 handler : "src.handler.handler" ,
121123 memorySize : 2048 ,
122124 logRetention : aws_logs . RetentionDays . ONE_WEEK ,
123125 timeout : Duration . seconds ( 30 ) ,
124- code :lambda . Code . fromDockerBuild ( __dirname , {
126+ code : lambda . Code . fromDockerBuild ( __dirname , {
125127 file : "runtime/Dockerfile" ,
126- buildArgs : { PYTHON_VERSION : '3.11' } ,
128+ buildArgs : {
129+ PYTHON_VERSION : "3.11" ,
130+ PGSTAC_VERSION : props . pgstacVersion || DEFAULT_PGSTAC_VERSION ,
131+ } ,
127132 } ) ,
128133 allowPublicSubnet : true ,
129134 vpc : props . dbVpc ,
@@ -139,7 +144,7 @@ export class StacIngestor extends Construct {
139144
140145 // Allow handler to connect to DB
141146
142- if ( props . dbVpc ) {
147+ if ( props . dbVpc ) {
143148 props . dbSecurityGroup . addIngressRule (
144149 handler . connections . securityGroups [ 0 ] ,
145150 ec2 . Port . tcp ( 5432 ) ,
@@ -160,10 +165,9 @@ export class StacIngestor extends Construct {
160165 dbSecurityGroup : ec2 . ISecurityGroup ;
161166 subnetSelection : undefined | ec2 . SubnetSelection ;
162167 lambdaFunctionOptions ?: CustomLambdaFunctionProps ;
168+ pgstacVersion ?: string ;
163169 } ) : lambda . Function {
164-
165-
166- const handler = new lambda . Function ( this , "stac-ingestor" , {
170+ const handler = new lambda . Function ( this , "stac-ingestor" , {
167171 // defaults
168172 runtime : lambda . Runtime . PYTHON_3_11 ,
169173 handler : "src.ingestor.handler" ,
@@ -172,7 +176,10 @@ export class StacIngestor extends Construct {
172176 timeout : Duration . seconds ( 180 ) ,
173177 code : lambda . Code . fromDockerBuild ( __dirname , {
174178 file : "runtime/Dockerfile" ,
175- buildArgs : { PYTHON_VERSION : '3.11' } ,
179+ buildArgs : {
180+ PYTHON_VERSION : "3.11" ,
181+ PGSTAC_VERSION : props . pgstacVersion || DEFAULT_PGSTAC_VERSION ,
182+ } ,
176183 } ) ,
177184 vpc : props . dbVpc ,
178185 vpcSubnets : props . subnetSelection ,
@@ -187,15 +194,15 @@ export class StacIngestor extends Construct {
187194 props . dbSecret . grantRead ( handler ) ;
188195
189196 // Allow handler to connect to DB
190- if ( props . dbVpc ) {
197+ if ( props . dbVpc ) {
191198 props . dbSecurityGroup . addIngressRule (
192199 handler . connections . securityGroups [ 0 ] ,
193200 ec2 . Port . tcp ( 5432 ) ,
194201 "Allow connections from STAC Ingestor"
195202 ) ;
196203 }
197204
198- // Allow handler to write results back to DBƒ
205+ // Allow handler to write results back to DB
199206 props . table . grantWriteData ( handler ) ;
200207
201208 // Trigger handler from writes to DynamoDB table
@@ -221,7 +228,6 @@ export class StacIngestor extends Construct {
221228 endpointConfiguration ?: apigateway . EndpointConfiguration ;
222229 ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
223230 } ) : apigateway . LambdaRestApi {
224-
225231 return new apigateway . LambdaRestApi (
226232 this ,
227233 `${ Stack . of ( this ) . stackName } -ingestor-api` ,
@@ -236,10 +242,12 @@ export class StacIngestor extends Construct {
236242 endpointConfiguration : props . endpointConfiguration ,
237243 policy : props . policy ,
238244
239- domainName : props . ingestorDomainNameOptions ? {
240- domainName : props . ingestorDomainNameOptions . domainName ,
241- certificate : props . ingestorDomainNameOptions . certificate ,
242- } : undefined ,
245+ domainName : props . ingestorDomainNameOptions
246+ ? {
247+ domainName : props . ingestorDomainNameOptions . domainName ,
248+ certificate : props . ingestorDomainNameOptions . certificate ,
249+ }
250+ : undefined ,
243251 }
244252 ) ;
245253 }
@@ -316,20 +324,26 @@ export interface StacIngestorProps {
316324 /**
317325 * Custom Domain Name Options for Ingestor API
318326 */
319- readonly ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
327+ readonly ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
320328
321329 /**
322- * Can be used to override the default lambda function properties.
323- *
324- * @default - default settings are defined in the construct.
325- */
330+ * Can be used to override the default lambda function properties.
331+ *
332+ * @default - default settings are defined in the construct.
333+ */
326334 readonly apiLambdaFunctionOptions ?: CustomLambdaFunctionProps ;
327335
328336 /**
329- * Can be used to override the default lambda function properties.
330- *
331- * @default - default settings are defined in the construct.
332- */
333- readonly ingestorLambdaFunctionOptions ?: CustomLambdaFunctionProps ;
337+ * Can be used to override the default lambda function properties.
338+ *
339+ * @default - default settings are defined in the construct.
340+ */
341+ readonly ingestorLambdaFunctionOptions ?: CustomLambdaFunctionProps ;
334342
343+ /**
344+ * pgstac version - must match the version installed on the pgstac database
345+ *
346+ * @default - default settings are defined in the construct
347+ */
348+ readonly pgstacVersion ?: string ;
335349}
0 commit comments