Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 8b7c989

Browse files
authored
feat: add support for Python 3.12 and Node 20 (#76)
1 parent 32d1e90 commit 8b7c989

7 files changed

+219
-131
lines changed

.projen/deps.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
1414
'typescript',
1515
'nodejs',
1616
],
17-
cdkVersion: '2.88.0',
17+
cdkVersion: '2.108.1',
1818
defaultReleaseBranch: 'main',
1919
minNodeVersion: '16.19.1',
2020
majorVersion: 3,

package.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lambda-powertools-layer.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
8080
const runtimeFamily = props?.runtimeFamily ?? lambda.RuntimeFamily.PYTHON;
8181
const languageName = getLanguageNameFromRuntimeFamily(runtimeFamily);
8282
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(', ');
8589

8690
console.log(`path ${dockerFilePath}`);
8791
super(scope, id, {
@@ -94,23 +98,35 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
9498
),
9599
},
96100
// supports cross-platform docker build
97-
platform: getDockerPlatformNameFromArchitectures(compatibleArchitectures),
101+
platform: getDockerPlatformNameFromArchitectures(
102+
compatibleArchitectures,
103+
),
98104
}),
99-
layerVersionName: props?.layerVersionName ? props?.layerVersionName : undefined,
105+
layerVersionName: props?.layerVersionName
106+
? props?.layerVersionName
107+
: undefined,
100108
license: 'MIT-0',
101109
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(),
105116
// 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?
106117
// Answer: on regions that don't support ARM64 Lambdas, we can't use the `compatibleArchitectures` parameter. Otherwise CloudFormation will bail with an error.
107118
// 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,
109123
});
110124
}
111125
}
112126

113-
function getRuntimesFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily): lambda.Runtime[] | undefined {
127+
function getRuntimesFromRuntimeFamily(
128+
runtimeFamily: lambda.RuntimeFamily,
129+
): lambda.Runtime[] | undefined {
114130
switch (runtimeFamily) {
115131
case lambda.RuntimeFamily.PYTHON:
116132
return [
@@ -119,20 +135,24 @@ function getRuntimesFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily): lamb
119135
lambda.Runtime.PYTHON_3_9,
120136
lambda.Runtime.PYTHON_3_10,
121137
lambda.Runtime.PYTHON_3_11,
138+
lambda.Runtime.PYTHON_3_12,
122139
];
123140
case lambda.RuntimeFamily.NODEJS:
124141
return [
125142
lambda.Runtime.NODEJS_12_X,
126143
lambda.Runtime.NODEJS_14_X,
127144
lambda.Runtime.NODEJS_16_X,
128145
lambda.Runtime.NODEJS_18_X,
146+
lambda.Runtime.NODEJS_20_X,
129147
];
130148
default:
131149
return [];
132150
}
133151
}
134152

135-
function getLanguageNameFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily): string {
153+
function getLanguageNameFromRuntimeFamily(
154+
runtimeFamily: lambda.RuntimeFamily,
155+
): string {
136156
switch (runtimeFamily) {
137157
case lambda.RuntimeFamily.PYTHON:
138158
return 'Python';
@@ -145,7 +165,9 @@ function getLanguageNameFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily):
145165

146166
// Docker expects a single string for the --platform option.
147167
// getDockerPlatformNameFromArchitectures converts the Architecture enum to a string.
148-
function getDockerPlatformNameFromArchitectures(architectures: lambda.Architecture[]): string {
168+
function getDockerPlatformNameFromArchitectures(
169+
architectures: lambda.Architecture[],
170+
): string {
149171
if (architectures.length == 1) {
150172
return architectures[0].dockerPlatform;
151173
} else {

test/lambda-powertools-python-layer.test.ts

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Template } from 'aws-cdk-lib/assertions';
33
import { Architecture, RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
44
import { LambdaPowertoolsLayer } from '../src';
55

6-
76
describe('with no configuration the construct', () => {
87
const stack = new Stack();
98
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer');
@@ -28,6 +27,7 @@ describe('with no configuration the construct', () => {
2827
'python3.9',
2928
'python3.10',
3029
'python3.11',
30+
'python3.12',
3131
],
3232
});
3333
});
@@ -55,9 +55,12 @@ describe('for layerVersionName configuraiton the construct', () => {
5555
layerVersionName: 'mySpecialName',
5656
});
5757

58-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
59-
LayerName: 'mySpecialName',
60-
});
58+
Template.fromStack(stack).hasResourceProperties(
59+
'AWS::Lambda::LayerVersion',
60+
{
61+
LayerName: 'mySpecialName',
62+
},
63+
);
6164
});
6265
});
6366

@@ -68,17 +71,23 @@ describe('with version configuration the construct', () => {
6871
version: '1.21.0',
6972
});
7073

71-
72-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
73-
Description: 'Powertools for AWS Lambda (Python) [x86_64] version 1.21.0',
74-
});
74+
Template.fromStack(stack).hasResourceProperties(
75+
'AWS::Lambda::LayerVersion',
76+
{
77+
Description:
78+
'Powertools for AWS Lambda (Python) [x86_64] version 1.21.0',
79+
},
80+
);
7581
});
7682

7783
test('fails with invalid version', () => {
7884
const stack = new Stack();
79-
expect(() => new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
80-
version: '0.0.0',
81-
})).toThrow(/docker exited with status 1/);
85+
expect(
86+
() =>
87+
new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
88+
version: '0.0.0',
89+
}),
90+
).toThrow(/docker exited with status 1/);
8291
});
8392

8493
test('synthesizes with pynadtic and specific version', () => {
@@ -88,10 +97,13 @@ describe('with version configuration the construct', () => {
8897
version: '1.22.0',
8998
});
9099

91-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
92-
Description: 'Powertools for AWS Lambda (Python) [x86_64] with extra dependencies version 1.22.0',
93-
});
94-
100+
Template.fromStack(stack).hasResourceProperties(
101+
'AWS::Lambda::LayerVersion',
102+
{
103+
Description:
104+
'Powertools for AWS Lambda (Python) [x86_64] with extra dependencies version 1.22.0',
105+
},
106+
);
95107
});
96108

97109
test('synthesizes with extras and latest version', () => {
@@ -100,49 +112,78 @@ describe('with version configuration the construct', () => {
100112
includeExtras: true,
101113
});
102114

103-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
104-
Description: 'Powertools for AWS Lambda (Python) [x86_64] with extra dependencies latest version',
105-
});
115+
Template.fromStack(stack).hasResourceProperties(
116+
'AWS::Lambda::LayerVersion',
117+
{
118+
Description:
119+
'Powertools for AWS Lambda (Python) [x86_64] with extra dependencies latest version',
120+
},
121+
);
106122
});
107123
});
108124

109125
describe('construct build args for Dockerfile', () => {
110126
test('returns extras and version', () => {
111-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, '1.21.0');
127+
const args = LambdaPowertoolsLayer.constructBuildArgs(
128+
RuntimeFamily.PYTHON,
129+
true,
130+
'1.21.0',
131+
);
112132

113133
expect(args).toEqual('[all]==1.21.0');
114134
});
115135

116136
test('returns only extras when no version provided', () => {
117-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, undefined);
137+
const args = LambdaPowertoolsLayer.constructBuildArgs(
138+
RuntimeFamily.PYTHON,
139+
true,
140+
undefined,
141+
);
118142

119143
expect(args).toEqual('[all]');
120144
});
121145

122146
test('returns a git url with extras when a git url is provided', () => {
123-
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
124-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, true, version);
147+
const version =
148+
'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
149+
const args = LambdaPowertoolsLayer.constructBuildArgs(
150+
RuntimeFamily.PYTHON,
151+
true,
152+
version,
153+
);
125154

126155
expect(args).toEqual(`[all] @ ${version}`);
127156
});
128157

129158
test('returns only version when no extras flag provided', () => {
130-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, '1.11.0');
159+
const args = LambdaPowertoolsLayer.constructBuildArgs(
160+
RuntimeFamily.PYTHON,
161+
undefined,
162+
'1.11.0',
163+
);
131164

132165
expect(args).toEqual('==1.11.0');
133166
});
134167

135168
test('returns empty when no version and extras provided', () => {
136-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, undefined, undefined);
169+
const args = LambdaPowertoolsLayer.constructBuildArgs(
170+
RuntimeFamily.PYTHON,
171+
undefined,
172+
undefined,
173+
);
137174

138175
expect(args).toEqual('');
139176
});
140177

141178
test('returns a git url when a git url is provided and extras provided', () => {
142-
const version = 'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
143-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.PYTHON, false, version);
179+
const version =
180+
'git+https://github.com/awslabs/aws-lambda-powertools-python@v2';
181+
const args = LambdaPowertoolsLayer.constructBuildArgs(
182+
RuntimeFamily.PYTHON,
183+
false,
184+
version,
185+
);
144186

145187
expect(args).toEqual(` @ ${version}`);
146188
});
147-
148189
});

test/lambda-powertools-typescript-layer.test.ts

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Template } from 'aws-cdk-lib/assertions';
33
import { RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
44
import { LambdaPowertoolsLayer } from '../src';
55

6-
76
describe('with minimal configuration the construct', () => {
87
const stack = new Stack();
98
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
@@ -12,7 +11,8 @@ describe('with minimal configuration the construct', () => {
1211
const template = Template.fromStack(stack);
1312
test('synthesizes successfully', () => {
1413
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
15-
Description: 'Powertools for AWS Lambda (TypeScript) [x86_64] latest version',
14+
Description:
15+
'Powertools for AWS Lambda (TypeScript) [x86_64] latest version',
1616
});
1717
});
1818

@@ -29,6 +29,7 @@ describe('with minimal configuration the construct', () => {
2929
'nodejs14.x',
3030
'nodejs16.x',
3131
'nodejs18.x',
32+
'nodejs20.x',
3233
],
3334
});
3435
});
@@ -41,9 +42,12 @@ describe('for layerVersionName configuration the construct', () => {
4142
layerVersionName: 'mySpecialName',
4243
});
4344

44-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
45-
LayerName: 'mySpecialName',
46-
});
45+
Template.fromStack(stack).hasResourceProperties(
46+
'AWS::Lambda::LayerVersion',
47+
{
48+
LayerName: 'mySpecialName',
49+
},
50+
);
4751
});
4852
});
4953

@@ -56,31 +60,42 @@ describe('with version configuration the construct', () => {
5660
version: version,
5761
});
5862

59-
60-
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::LayerVersion', {
61-
Description: `Powertools for AWS Lambda (TypeScript) [x86_64] version ${version}`,
62-
});
63+
Template.fromStack(stack).hasResourceProperties(
64+
'AWS::Lambda::LayerVersion',
65+
{
66+
Description: `Powertools for AWS Lambda (TypeScript) [x86_64] version ${version}`,
67+
},
68+
);
6369
});
6470

6571
test('fails with invalid version', () => {
6672
const stack = new Stack();
67-
expect(() => new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
68-
runtimeFamily: RuntimeFamily.NODEJS,
69-
version: '12.222.21123',
70-
})).toThrow();
73+
expect(
74+
() =>
75+
new LambdaPowertoolsLayer(stack, 'PowertoolsLayerBadVersion', {
76+
runtimeFamily: RuntimeFamily.NODEJS,
77+
version: '12.222.21123',
78+
}),
79+
).toThrow();
7180
});
7281

73-
7482
test('returns version with @ when provided provided', () => {
75-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.NODEJS, undefined, '0.9.0');
83+
const args = LambdaPowertoolsLayer.constructBuildArgs(
84+
RuntimeFamily.NODEJS,
85+
undefined,
86+
'0.9.0',
87+
);
7688

7789
expect(args).toEqual('@0.9.0');
7890
});
7991

8092
test('returns empty when no version provided', () => {
81-
const args = LambdaPowertoolsLayer.constructBuildArgs(RuntimeFamily.NODEJS, undefined, undefined);
93+
const args = LambdaPowertoolsLayer.constructBuildArgs(
94+
RuntimeFamily.NODEJS,
95+
undefined,
96+
undefined,
97+
);
8298

8399
expect(args).toEqual('');
84100
});
85-
86101
});

0 commit comments

Comments
 (0)