@@ -13,7 +13,7 @@ import {
13
13
Stack ,
14
14
} from "aws-cdk-lib" ;
15
15
import { Construct } from "constructs" ;
16
- import { CustomLambdaFunctionProps } from "../utils" ;
16
+ import { CustomLambdaFunctionProps , DEFAULT_PGSTAC_VERSION } from "../utils" ;
17
17
18
18
export class StacIngestor extends Construct {
19
19
table : dynamodb . Table ;
@@ -39,10 +39,10 @@ export class StacIngestor extends Construct {
39
39
assumedBy : new iam . ServicePrincipal ( "lambda.amazonaws.com" ) ,
40
40
managedPolicies : [
41
41
iam . ManagedPolicy . fromAwsManagedPolicyName (
42
- "service-role/AWSLambdaBasicExecutionRole" ,
42
+ "service-role/AWSLambdaBasicExecutionRole"
43
43
) ,
44
44
iam . ManagedPolicy . fromAwsManagedPolicyName (
45
- "service-role/AWSLambdaVPCAccessExecutionRole" ,
45
+ "service-role/AWSLambdaVPCAccessExecutionRole"
46
46
) ,
47
47
] ,
48
48
} ) ;
@@ -57,6 +57,7 @@ export class StacIngestor extends Construct {
57
57
dbSecurityGroup : props . stacDbSecurityGroup ,
58
58
subnetSelection : props . subnetSelection ,
59
59
lambdaFunctionOptions : props . apiLambdaFunctionOptions ,
60
+ pgstacVersion : props . pgstacVersion ,
60
61
} ) ;
61
62
62
63
this . buildApiEndpoint ( {
@@ -74,7 +75,8 @@ export class StacIngestor extends Construct {
74
75
dbVpc : props . vpc ,
75
76
dbSecurityGroup : props . stacDbSecurityGroup ,
76
77
subnetSelection : props . subnetSelection ,
77
- lambdaFunctionOptions : props . ingestorLambdaFunctionOptions
78
+ lambdaFunctionOptions : props . ingestorLambdaFunctionOptions ,
79
+ pgstacVersion : props . pgstacVersion ,
78
80
} ) ;
79
81
80
82
this . registerSsmParameter ( {
@@ -110,20 +112,23 @@ export class StacIngestor extends Construct {
110
112
dbSecret : secretsmanager . ISecret ;
111
113
dbVpc : undefined | ec2 . IVpc ;
112
114
dbSecurityGroup : ec2 . ISecurityGroup ;
113
- subnetSelection : undefined | ec2 . SubnetSelection
115
+ subnetSelection : undefined | ec2 . SubnetSelection ;
114
116
lambdaFunctionOptions ?: CustomLambdaFunctionProps ;
117
+ pgstacVersion ?: string ;
115
118
} ) : lambda . Function {
116
-
117
119
const handler = new lambda . Function ( this , "api-handler" , {
118
120
// defaults
119
121
runtime : lambda . Runtime . PYTHON_3_11 ,
120
122
handler : "src.handler.handler" ,
121
123
memorySize : 2048 ,
122
124
logRetention : aws_logs . RetentionDays . ONE_WEEK ,
123
125
timeout : Duration . seconds ( 30 ) ,
124
- code :lambda . Code . fromDockerBuild ( __dirname , {
126
+ code : lambda . Code . fromDockerBuild ( __dirname , {
125
127
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
+ } ,
127
132
} ) ,
128
133
allowPublicSubnet : true ,
129
134
vpc : props . dbVpc ,
@@ -139,7 +144,7 @@ export class StacIngestor extends Construct {
139
144
140
145
// Allow handler to connect to DB
141
146
142
- if ( props . dbVpc ) {
147
+ if ( props . dbVpc ) {
143
148
props . dbSecurityGroup . addIngressRule (
144
149
handler . connections . securityGroups [ 0 ] ,
145
150
ec2 . Port . tcp ( 5432 ) ,
@@ -160,10 +165,9 @@ export class StacIngestor extends Construct {
160
165
dbSecurityGroup : ec2 . ISecurityGroup ;
161
166
subnetSelection : undefined | ec2 . SubnetSelection ;
162
167
lambdaFunctionOptions ?: CustomLambdaFunctionProps ;
168
+ pgstacVersion ?: string ;
163
169
} ) : lambda . Function {
164
-
165
-
166
- const handler = new lambda . Function ( this , "stac-ingestor" , {
170
+ const handler = new lambda . Function ( this , "stac-ingestor" , {
167
171
// defaults
168
172
runtime : lambda . Runtime . PYTHON_3_11 ,
169
173
handler : "src.ingestor.handler" ,
@@ -172,7 +176,10 @@ export class StacIngestor extends Construct {
172
176
timeout : Duration . seconds ( 180 ) ,
173
177
code : lambda . Code . fromDockerBuild ( __dirname , {
174
178
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
+ } ,
176
183
} ) ,
177
184
vpc : props . dbVpc ,
178
185
vpcSubnets : props . subnetSelection ,
@@ -187,15 +194,15 @@ export class StacIngestor extends Construct {
187
194
props . dbSecret . grantRead ( handler ) ;
188
195
189
196
// Allow handler to connect to DB
190
- if ( props . dbVpc ) {
197
+ if ( props . dbVpc ) {
191
198
props . dbSecurityGroup . addIngressRule (
192
199
handler . connections . securityGroups [ 0 ] ,
193
200
ec2 . Port . tcp ( 5432 ) ,
194
201
"Allow connections from STAC Ingestor"
195
202
) ;
196
203
}
197
204
198
- // Allow handler to write results back to DBƒ
205
+ // Allow handler to write results back to DB
199
206
props . table . grantWriteData ( handler ) ;
200
207
201
208
// Trigger handler from writes to DynamoDB table
@@ -221,7 +228,6 @@ export class StacIngestor extends Construct {
221
228
endpointConfiguration ?: apigateway . EndpointConfiguration ;
222
229
ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
223
230
} ) : apigateway . LambdaRestApi {
224
-
225
231
return new apigateway . LambdaRestApi (
226
232
this ,
227
233
`${ Stack . of ( this ) . stackName } -ingestor-api` ,
@@ -236,10 +242,12 @@ export class StacIngestor extends Construct {
236
242
endpointConfiguration : props . endpointConfiguration ,
237
243
policy : props . policy ,
238
244
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 ,
243
251
}
244
252
) ;
245
253
}
@@ -316,20 +324,26 @@ export interface StacIngestorProps {
316
324
/**
317
325
* Custom Domain Name Options for Ingestor API
318
326
*/
319
- readonly ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
327
+ readonly ingestorDomainNameOptions ?: apigateway . DomainNameOptions ;
320
328
321
329
/**
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
+ */
326
334
readonly apiLambdaFunctionOptions ?: CustomLambdaFunctionProps ;
327
335
328
336
/**
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 ;
334
342
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 ;
335
349
}
0 commit comments