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

Commit 67aeb16

Browse files
committed
feat: add support for Python 3.12 and Node 20
1 parent 32d1e90 commit 67aeb16

File tree

8 files changed

+410
-276
lines changed

8 files changed

+410
-276
lines changed

.projen/deps.json

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

.projen/tasks.json

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

.projenrc.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
const { awscdk } = require('projen');
1+
const { awscdk } = require("projen");
22
const project = new awscdk.AwsCdkConstructLibrary({
3-
authorName: 'Amazon Web Services',
4-
authorUrl: 'https://aws.amazon.com',
3+
authorName: "Amazon Web Services",
4+
authorUrl: "https://aws.amazon.com",
55
authorOrganization: true,
66
keywords: [
7-
'aws',
8-
'cdk',
9-
'powertools',
10-
'python',
11-
'layer',
12-
'lambda',
13-
'devax',
14-
'typescript',
15-
'nodejs',
7+
"aws",
8+
"cdk",
9+
"powertools",
10+
"python",
11+
"layer",
12+
"lambda",
13+
"devax",
14+
"typescript",
15+
"nodejs",
1616
],
17-
cdkVersion: '2.88.0',
18-
defaultReleaseBranch: 'main',
19-
minNodeVersion: '16.19.1',
17+
cdkVersion: "2.108.1",
18+
defaultReleaseBranch: "main",
19+
minNodeVersion: "16.19.1",
2020
majorVersion: 3,
21-
name: 'cdk-aws-lambda-powertools-layer',
21+
name: "cdk-aws-lambda-powertools-layer",
2222
repositoryUrl:
23-
'https://github.com/awslabs/cdk-aws-lambda-powertools-layer.git',
24-
description: 'Powertools for AWS Lambda layer for python and typescript',
23+
"https://github.com/awslabs/cdk-aws-lambda-powertools-layer.git",
24+
description: "Powertools for AWS Lambda layer for python and typescript",
2525
devDeps: [
26-
'@types/[email protected]', // pin until breaking changes is resolved: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60310
26+
"@types/[email protected]", // pin until breaking changes is resolved: https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/60310
2727
],
2828
github: false,
2929
publishToPypi: {
30-
distName: 'cdk-aws-lambda-powertools-layer',
31-
module: 'cdk_aws_lambda_powertools_layer',
30+
distName: "cdk-aws-lambda-powertools-layer",
31+
module: "cdk_aws_lambda_powertools_layer",
3232
},
33-
license: 'MIT-0',
34-
copyrightOwner: 'Amazon.com, Inc. or its affiliates. All Rights Reserved.',
33+
license: "MIT-0",
34+
copyrightOwner: "Amazon.com, Inc. or its affiliates. All Rights Reserved.",
3535
});
3636

3737
project.synth();

package.json

Lines changed: 4 additions & 4 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: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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";
55

66
/**
77
* Properties for Powertools for AWS Lambda (Python) Layer.
@@ -49,16 +49,16 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
4949
static constructBuildArgs(
5050
runtimeFamily: lambda.RuntimeFamily,
5151
includeExtras: boolean | undefined,
52-
version: string | undefined,
52+
version: string | undefined
5353
): string {
54-
let suffix = '';
54+
let suffix = "";
5555
switch (runtimeFamily) {
5656
case lambda.RuntimeFamily.PYTHON:
5757
if (includeExtras) {
58-
suffix = '[all]';
58+
suffix = "[all]";
5959
}
6060
if (version) {
61-
if (version.startsWith('git')) {
61+
if (version.startsWith("git")) {
6262
suffix = `${suffix} @ ${version}`;
6363
} else {
6464
suffix = `${suffix}==${version}`;
@@ -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, {
@@ -90,27 +94,39 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
9094
PACKAGE_SUFFIX: LambdaPowertoolsLayer.constructBuildArgs(
9195
runtimeFamily,
9296
props?.includeExtras,
93-
props?.version,
97+
props?.version
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,
100-
license: 'MIT-0',
105+
layerVersionName: props?.layerVersionName
106+
? props?.layerVersionName
107+
: undefined,
108+
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,33 +135,39 @@ 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:
138-
return 'Python';
158+
return "Python";
139159
case lambda.RuntimeFamily.NODEJS:
140-
return 'TypeScript';
160+
return "TypeScript";
141161
default:
142-
return 'Unknown';
162+
return "Unknown";
143163
}
144164
}
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 {

0 commit comments

Comments
 (0)