@@ -130,14 +130,15 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
130
130
private readonly provider : lambda . Function ;
131
131
private readonly targetDirectory : string ;
132
132
private readonly type : DependencyPackagerType ;
133
+ private readonly runtime : lambda . Runtime ;
133
134
private readonly architecture : lambda . Architecture ;
134
135
135
136
constructor ( scope : Construct , id : string , readonly internalProps : InternalBaseDependencyPackagerProps ) {
136
137
super ( scope , id ) ;
137
138
138
- const runtime = internalProps . props ?. runtime ?? internalProps . defaultRuntime ;
139
- if ( runtime . family != internalProps . runtimeFamily ) {
140
- throw new Error ( `PythonDependencyPackager requires python runtime, got ${ runtime . family } ` ) ;
139
+ this . runtime = internalProps . props ?. runtime ?? internalProps . defaultRuntime ;
140
+ if ( this . runtime . family != internalProps . runtimeFamily ) {
141
+ throw new Error ( `PythonDependencyPackager requires python runtime, got ${ this . runtime . family } ` ) ;
141
142
}
142
143
143
144
this . packagesBucket = new s3 . Bucket ( this , 'Bucket' , {
@@ -163,7 +164,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
163
164
) ;
164
165
165
166
this . project = new codebuild . Project ( this , 'Packager' , {
166
- description : `Lambda dependency packager for ${ runtime } in ${ Stack . of ( this ) . stackName } ` ,
167
+ description : `Lambda dependency packager for ${ this . runtime } in ${ Stack . of ( this ) . stackName } ` ,
167
168
vpc : internalProps . props ?. vpc ,
168
169
subnetSelection : internalProps . props ?. subnetSelection ,
169
170
environment : {
@@ -192,7 +193,7 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
192
193
this . grantPrincipal = this . project . grantPrincipal ;
193
194
194
195
this . provider = new PackageCodebuildFunction ( this , 'Package Handler' , {
195
- description : `Turbo layer packager for ${ runtime } using CodeBuild` ,
196
+ description : `Turbo layer packager for ${ this . runtime } using CodeBuild` ,
196
197
initialPolicy : [
197
198
new iam . PolicyStatement ( {
198
199
actions : [ 'codebuild:StartBuild' ] ,
@@ -206,8 +207,8 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
206
207
this . packagesBucket . grantDelete ( this . provider ) ;
207
208
} else if ( this . type == DependencyPackagerType . LAMBDA ) {
208
209
const lambdaProps = {
209
- description : `Turbo layer packager for ${ runtime } ` ,
210
- runtime : runtime ,
210
+ description : `Turbo layer packager for ${ this . runtime } ` ,
211
+ runtime : this . runtime ,
211
212
timeout : Duration . minutes ( 15 ) ,
212
213
memorySize : 1024 ,
213
214
ephemeralStorageSize : Size . gibibytes ( 10 ) ,
@@ -218,19 +219,19 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
218
219
// TODO for CodeArtifact login -- layers: [new lambda_layer_awscli.AwsCliLayer(this, 'AWS CLI Layer')],
219
220
} ;
220
221
221
- if ( runtime . family == lambda . RuntimeFamily . PYTHON ) {
222
+ if ( this . runtime . family == lambda . RuntimeFamily . PYTHON ) {
222
223
this . provider = new PackagePythonFunction ( this , 'Packager' , lambdaProps ) ;
223
- } else if ( runtime . family == lambda . RuntimeFamily . NODEJS ) {
224
+ } else if ( this . runtime . family == lambda . RuntimeFamily . NODEJS ) {
224
225
this . provider = new PackageNodejsFunction ( this , 'Packager' , lambdaProps ) ;
225
226
// we can't set the runtime from here, so we have to manually override it.
226
227
// projen puts `...props` before its own `runtime` setting and so its default `runtime` always wins.
227
228
// https://github.com/projen/projen/blob/564341a55309e06939c86248bc76cabc590fd835/src/awscdk/lambda-function.ts#L253-L256
228
229
const func = this . provider . node . defaultChild as lambda . CfnFunction ;
229
- func . runtime = runtime . name ;
230
- } else if ( runtime . family == lambda . RuntimeFamily . RUBY ) {
230
+ func . runtime = this . runtime . name ;
231
+ } else if ( this . runtime . family == lambda . RuntimeFamily . RUBY ) {
231
232
this . provider = new PackageRubyFunction ( this , 'Packager' , lambdaProps ) ;
232
233
} else {
233
- throw new Error ( `Runtime doesn't support Lambda packager: ${ runtime } ` ) ;
234
+ throw new Error ( `Runtime doesn't support Lambda packager: ${ this . runtime } ` ) ;
234
235
}
235
236
this . connections = internalProps . props ?. vpc ? this . provider . connections : new ec2 . Connections ( ) ;
236
237
this . grantPrincipal = this . provider . grantPrincipal ;
@@ -270,6 +271,8 @@ export class BaseDependencyPackager extends Construct implements iam.IGrantable,
270
271
codeBuildRuntimeInstallCommands : this . internalProps . codeBuildRuntimeInstallCommands ,
271
272
commands : commands ,
272
273
targetDirectory : this . targetDirectory ,
274
+ runtime : this . runtime ,
275
+ architecture : this . architecture ,
273
276
} ) . layer ;
274
277
}
275
278
@@ -306,6 +309,8 @@ interface LambdaDependencyLayerProps {
306
309
readonly preinstallCommands : string [ ] ;
307
310
readonly commands : string [ ] ;
308
311
readonly targetDirectory : string ;
312
+ readonly runtime : lambda . Runtime ;
313
+ readonly architecture : lambda . Architecture ;
309
314
}
310
315
311
316
class LambdaDependencyLayer extends Construct {
@@ -353,6 +358,8 @@ class LambdaDependencyLayer extends Construct {
353
358
this . layer = new lambda . LayerVersion ( this , 'Layer' , {
354
359
description : `Automatically generated by turbo layers for ${ asset } ` ,
355
360
code : lambda . Code . fromBucket ( props . packagesBucket , cr . ref ) ,
361
+ compatibleRuntimes : [ props . runtime ] ,
362
+ compatibleArchitectures : [ props . architecture ] ,
356
363
} ) ;
357
364
}
358
365
}
0 commit comments