1
- import * as path from ' path' ;
2
- import { aws_lambda as lambda } from ' aws-cdk-lib' ;
3
- import { Architecture } from ' aws-cdk-lib/aws-lambda' ;
4
- import { Construct } from ' constructs' ;
1
+ import * as path from " path" ;
2
+ import { aws_lambda as lambda } from " aws-cdk-lib" ;
3
+ import { Architecture } from " aws-cdk-lib/aws-lambda" ;
4
+ import { Construct } from " constructs" ;
5
5
6
6
/**
7
7
* Properties for Powertools for AWS Lambda (Python) Layer.
@@ -49,16 +49,16 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
49
49
static constructBuildArgs (
50
50
runtimeFamily : lambda . RuntimeFamily ,
51
51
includeExtras : boolean | undefined ,
52
- version : string | undefined ,
52
+ version : string | undefined
53
53
) : string {
54
- let suffix = '' ;
54
+ let suffix = "" ;
55
55
switch ( runtimeFamily ) {
56
56
case lambda . RuntimeFamily . PYTHON :
57
57
if ( includeExtras ) {
58
- suffix = ' [all]' ;
58
+ suffix = " [all]" ;
59
59
}
60
60
if ( version ) {
61
- if ( version . startsWith ( ' git' ) ) {
61
+ if ( version . startsWith ( " git" ) ) {
62
62
suffix = `${ suffix } @ ${ version } ` ;
63
63
} else {
64
64
suffix = `${ suffix } ==${ version } ` ;
@@ -80,8 +80,12 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
80
80
const runtimeFamily = props ?. runtimeFamily ?? lambda . RuntimeFamily . PYTHON ;
81
81
const languageName = getLanguageNameFromRuntimeFamily ( runtimeFamily ) ;
82
82
const dockerFilePath = path . join ( __dirname , `../layer/${ languageName } ` ) ;
83
- const compatibleArchitectures = props ?. compatibleArchitectures ?? [ lambda . Architecture . X86_64 ] ;
84
- const compatibleArchitecturesDescription = compatibleArchitectures . map ( ( arch ) => arch . name ) . join ( ', ' ) ;
83
+ const compatibleArchitectures = props ?. compatibleArchitectures ?? [
84
+ lambda . Architecture . X86_64 ,
85
+ ] ;
86
+ const compatibleArchitecturesDescription = compatibleArchitectures
87
+ . map ( ( arch ) => arch . name )
88
+ . join ( ", " ) ;
85
89
86
90
console . log ( `path ${ dockerFilePath } ` ) ;
87
91
super ( scope , id , {
@@ -90,27 +94,39 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
90
94
PACKAGE_SUFFIX : LambdaPowertoolsLayer . constructBuildArgs (
91
95
runtimeFamily ,
92
96
props ?. includeExtras ,
93
- props ?. version ,
97
+ props ?. version
94
98
) ,
95
99
} ,
96
100
// supports cross-platform docker build
97
- platform : getDockerPlatformNameFromArchitectures ( compatibleArchitectures ) ,
101
+ platform : getDockerPlatformNameFromArchitectures (
102
+ compatibleArchitectures
103
+ ) ,
98
104
} ) ,
99
- layerVersionName : props ?. layerVersionName ? props ?. layerVersionName : undefined ,
100
- license : 'MIT-0' ,
105
+ layerVersionName : props ?. layerVersionName
106
+ ? props ?. layerVersionName
107
+ : undefined ,
108
+ license : "MIT-0" ,
101
109
compatibleRuntimes : getRuntimesFromRuntimeFamily ( runtimeFamily ) ,
102
- description : `Powertools for AWS Lambda (${ languageName } ) [${ compatibleArchitecturesDescription } ]${
103
- props ?. includeExtras ? ' with extra dependencies' : ''
104
- } ${ props ?. version ? `version ${ props ?. version } ` : 'latest version' } `. trim ( ) ,
110
+ description :
111
+ `Powertools for AWS Lambda (${ languageName } ) [${ compatibleArchitecturesDescription } ]${
112
+ props ?. includeExtras ? " with extra dependencies" : ""
113
+ } ${
114
+ props ?. version ? `version ${ props ?. version } ` : "latest version"
115
+ } `. trim ( ) ,
105
116
// Dear reader: I'm happy that you've stumbled upon this line too! You might wonder, why are we doing this and passing `undefined` when the list is empty?
106
117
// Answer: on regions that don't support ARM64 Lambdas, we can't use the `compatibleArchitectures` parameter. Otherwise CloudFormation will bail with an error.
107
118
// So if this construct is called with en empty list of architectures, just pass undefined down to the CDK construct.
108
- compatibleArchitectures : compatibleArchitectures . length == 0 ? undefined : compatibleArchitectures ,
119
+ compatibleArchitectures :
120
+ compatibleArchitectures . length == 0
121
+ ? undefined
122
+ : compatibleArchitectures ,
109
123
} ) ;
110
124
}
111
125
}
112
126
113
- function getRuntimesFromRuntimeFamily ( runtimeFamily : lambda . RuntimeFamily ) : lambda . Runtime [ ] | undefined {
127
+ function getRuntimesFromRuntimeFamily (
128
+ runtimeFamily : lambda . RuntimeFamily
129
+ ) : lambda . Runtime [ ] | undefined {
114
130
switch ( runtimeFamily ) {
115
131
case lambda . RuntimeFamily . PYTHON :
116
132
return [
@@ -119,33 +135,39 @@ function getRuntimesFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily): lamb
119
135
lambda . Runtime . PYTHON_3_9 ,
120
136
lambda . Runtime . PYTHON_3_10 ,
121
137
lambda . Runtime . PYTHON_3_11 ,
138
+ lambda . Runtime . PYTHON_3_12 ,
122
139
] ;
123
140
case lambda . RuntimeFamily . NODEJS :
124
141
return [
125
142
lambda . Runtime . NODEJS_12_X ,
126
143
lambda . Runtime . NODEJS_14_X ,
127
144
lambda . Runtime . NODEJS_16_X ,
128
145
lambda . Runtime . NODEJS_18_X ,
146
+ lambda . Runtime . NODEJS_20_X ,
129
147
] ;
130
148
default :
131
149
return [ ] ;
132
150
}
133
151
}
134
152
135
- function getLanguageNameFromRuntimeFamily ( runtimeFamily : lambda . RuntimeFamily ) : string {
153
+ function getLanguageNameFromRuntimeFamily (
154
+ runtimeFamily : lambda . RuntimeFamily
155
+ ) : string {
136
156
switch ( runtimeFamily ) {
137
157
case lambda . RuntimeFamily . PYTHON :
138
- return ' Python' ;
158
+ return " Python" ;
139
159
case lambda . RuntimeFamily . NODEJS :
140
- return ' TypeScript' ;
160
+ return " TypeScript" ;
141
161
default :
142
- return ' Unknown' ;
162
+ return " Unknown" ;
143
163
}
144
164
}
145
165
146
166
// Docker expects a single string for the --platform option.
147
167
// getDockerPlatformNameFromArchitectures converts the Architecture enum to a string.
148
- function getDockerPlatformNameFromArchitectures ( architectures : lambda . Architecture [ ] ) : string {
168
+ function getDockerPlatformNameFromArchitectures (
169
+ architectures : lambda . Architecture [ ]
170
+ ) : string {
149
171
if ( architectures . length == 1 ) {
150
172
return architectures [ 0 ] . dockerPlatform ;
151
173
} else {
0 commit comments