Skip to content

Commit 1b39b7c

Browse files
author
Eugene Cheung
authored
feat: use dynamically determined latest Node.js runtime for Lambda handlers instead (#641)
`NODEJS_LATEST` still points to Node.js 18, which is already EOL. Related upstream issue: aws/aws-cdk#28125 --- _By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license_
1 parent 7b7d081 commit 1b39b7c

File tree

12 files changed

+209
-48
lines changed

12 files changed

+209
-48
lines changed

lib/dashboard/widget/BitmapWidget.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import * as path from "path";
33
import { Duration, Tags } from "aws-cdk-lib";
44
import { IWidget } from "aws-cdk-lib/aws-cloudwatch";
55
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
6-
import { Code, Function, IFunction, Runtime } from "aws-cdk-lib/aws-lambda";
6+
import {
7+
Code,
8+
determineLatestNodeRuntime,
9+
Function,
10+
IFunction,
11+
} from "aws-cdk-lib/aws-lambda";
712
import { RetentionDays } from "aws-cdk-lib/aws-logs";
813
import { Construct } from "constructs";
914

@@ -34,7 +39,7 @@ export class BitmapWidgetRenderingSupport extends Construct {
3439
"Custom Widget Render for Bitmap Widgets (cdk-monitoring-constructs)",
3540
handler: "index.handler",
3641
memorySize: 128,
37-
runtime: Runtime.NODEJS_LATEST,
42+
runtime: determineLatestNodeRuntime(this),
3843
timeout: Duration.seconds(60),
3944
logRetention: RetentionDays.ONE_DAY,
4045
});

lib/monitoring/aws-secretsmanager/SecretsManagerMetricsPublisher.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { Duration, Names } from "aws-cdk-lib";
44
import { Rule, RuleTargetInput, Schedule } from "aws-cdk-lib/aws-events";
55
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
66
import { Effect, PolicyStatement } from "aws-cdk-lib/aws-iam";
7-
import { Code, Function, IFunction, Runtime } from "aws-cdk-lib/aws-lambda";
7+
import {
8+
Code,
9+
determineLatestNodeRuntime,
10+
Function,
11+
IFunction,
12+
} from "aws-cdk-lib/aws-lambda";
813
import { RetentionDays } from "aws-cdk-lib/aws-logs";
914
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
1015
import { Construct } from "constructs";
@@ -34,7 +39,7 @@ export class SecretsManagerMetricsPublisher extends Construct {
3439
"Custom metrics publisher for SecretsManager Secrets (cdk-monitoring-constructs)",
3540
handler: "index.handler",
3641
memorySize: 128,
37-
runtime: Runtime.NODEJS_LATEST,
42+
runtime: determineLatestNodeRuntime(this),
3843
timeout: Duration.seconds(60),
3944
logRetention: RetentionDays.ONE_DAY,
4045
});

test/common/alarm/action/LambdaAlarmActionStrategy.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import { Stack } from "aws-cdk-lib";
22
import { Template } from "aws-cdk-lib/assertions";
33
import { Alarm, Metric } from "aws-cdk-lib/aws-cloudwatch";
4-
import { Function, InlineCode, Runtime } from "aws-cdk-lib/aws-lambda";
4+
import {
5+
determineLatestNodeRuntime,
6+
Function,
7+
InlineCode,
8+
} from "aws-cdk-lib/aws-lambda";
59

610
import { LambdaAlarmActionStrategy } from "../../../../lib";
711

812
test("snapshot test: Lambda function", () => {
913
const stack = new Stack();
1014
const onAlarmFunction = new Function(stack, "alarmLambda", {
1115
functionName: "DummyLambda",
12-
runtime: Runtime.NODEJS_LATEST,
16+
runtime: determineLatestNodeRuntime(stack),
1317
code: InlineCode.fromInline("{}"),
1418
handler: "Dummy::handler",
1519
});
@@ -28,7 +32,7 @@ test("snapshot test: Lambda alias", () => {
2832
const stack = new Stack();
2933
const onAlarmFunction = new Function(stack, "alarmLambda", {
3034
functionName: "DummyLambda",
31-
runtime: Runtime.NODEJS_LATEST,
35+
runtime: determineLatestNodeRuntime(stack),
3236
code: InlineCode.fromInline("{}"),
3337
handler: "Dummy::handler",
3438
});
@@ -48,7 +52,7 @@ test("snapshot test: Lambda version", () => {
4852
const stack = new Stack();
4953
const onAlarmFunction = new Function(stack, "alarmLambda", {
5054
functionName: "DummyLambda",
51-
runtime: Runtime.NODEJS_LATEST,
55+
runtime: determineLatestNodeRuntime(stack),
5256
code: InlineCode.fromInline("{}"),
5357
handler: "Dummy::handler",
5458
});

test/common/alarm/action/__snapshots__/LambdaAlarmActionStrategy.test.ts.snap

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

test/dashboard/widget/CustomWidget.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import { Stack } from "aws-cdk-lib";
2-
import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";
2+
import {
3+
Code,
4+
determineLatestNodeRuntime,
5+
Function,
6+
} from "aws-cdk-lib/aws-lambda";
37

48
import { CustomWidget } from "../../../lib/dashboard/widget/CustomWidget";
59

610
test("widget", () => {
711
const stack = new Stack();
812

913
const handler = new Function(stack, "Function", {
10-
// execution environment
11-
runtime: Runtime.NODEJS_LATEST,
14+
runtime: determineLatestNodeRuntime(stack),
1215
// code loaded from "lambda" directory
1316
code: Code.fromInline(
1417
'exports.handler = function(event, ctx, cb) { return cb(null, "Hello World!"); }',

test/dashboard/widget/__snapshots__/BitmapWidget.test.ts.snap

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

test/facade/__snapshots__/MonitoringAspect.test.ts.snap

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

test/monitoring/aws-lambda/LambdaFunctionMonitoring.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Duration, Stack } from "aws-cdk-lib";
22
import { Template } from "aws-cdk-lib/assertions";
33
import { Color, ComparisonOperator } from "aws-cdk-lib/aws-cloudwatch";
44
import {
5+
determineLatestNodeRuntime,
56
Function,
67
InlineCode,
78
LayerVersion,
8-
Runtime,
99
} from "aws-cdk-lib/aws-lambda";
1010

1111
import { AlarmWithAnnotation, LambdaFunctionMonitoring } from "../../../lib";
@@ -19,7 +19,7 @@ test("snapshot test: default iterator and no alarms", () => {
1919

2020
const lambdaFunction = new Function(stack, "Function", {
2121
functionName: "DummyLambda",
22-
runtime: Runtime.NODEJS_LATEST,
22+
runtime: determineLatestNodeRuntime(stack),
2323
code: InlineCode.fromInline("{}"),
2424
handler: "Dummy::handler",
2525
});
@@ -49,7 +49,7 @@ test("snapshot test: non-iterator and no alarms", () => {
4949

5050
const lambdaFunction = new Function(stack, "Function", {
5151
functionName: "DummyLambda",
52-
runtime: Runtime.NODEJS_LATEST,
52+
runtime: determineLatestNodeRuntime(stack),
5353
code: InlineCode.fromInline("{}"),
5454
handler: "Dummy::handler",
5555
});
@@ -72,7 +72,7 @@ test("snapshot test: all alarms", () => {
7272

7373
const lambdaFunction = new Function(stack, "Function", {
7474
functionName: "DummyLambda",
75-
runtime: Runtime.NODEJS_LATEST,
75+
runtime: determineLatestNodeRuntime(stack),
7676
code: InlineCode.fromInline("{}"),
7777
handler: "Dummy::handler",
7878
});
@@ -190,7 +190,7 @@ test("snapshot test: all alarms", () => {
190190

191191
const lambdaFunction = new Function(stack, "Function", {
192192
functionName: "DummyLambda",
193-
runtime: Runtime.NODEJS_LATEST,
193+
runtime: determineLatestNodeRuntime(stack),
194194
code: InlineCode.fromInline("{}"),
195195
handler: "Dummy::handler",
196196
layers: [
@@ -230,7 +230,7 @@ test("snapshot test: all alarms, alarmPrefix on error dedupeString", () => {
230230

231231
const lambdaFunction = new Function(stack, "Function", {
232232
functionName: "DummyLambda",
233-
runtime: Runtime.NODEJS_LATEST,
233+
runtime: determineLatestNodeRuntime(stack),
234234
code: InlineCode.fromInline("{}"),
235235
handler: "Dummy::handler",
236236
});
@@ -376,7 +376,7 @@ test("snapshot test: all alarms, alarmPrefix on latency dedupeString", () => {
376376

377377
const lambdaFunction = new Function(stack, "Function", {
378378
functionName: "DummyLambda",
379-
runtime: Runtime.NODEJS_LATEST,
379+
runtime: determineLatestNodeRuntime(stack),
380380
code: InlineCode.fromInline("{}"),
381381
handler: "Dummy::handler",
382382
});
@@ -519,7 +519,7 @@ test("throws error if attempting to create iterator age alarm if not an iterator
519519

520520
const lambdaFunction = new Function(stack, "Function", {
521521
functionName: "DummyLambda",
522-
runtime: Runtime.NODEJS_LATEST,
522+
runtime: determineLatestNodeRuntime(stack),
523523
code: InlineCode.fromInline("{}"),
524524
handler: "Dummy::handler",
525525
});
@@ -549,7 +549,7 @@ test("throws error if attempting to create offsetLag alarm if not an offsetLag L
549549

550550
const lambdaFunction = new Function(stack, "Function", {
551551
functionName: "DummyLambda",
552-
runtime: Runtime.NODEJS_LATEST,
552+
runtime: determineLatestNodeRuntime(stack),
553553
code: InlineCode.fromInline("{}"),
554554
handler: "Dummy::handler",
555555
});
@@ -578,7 +578,7 @@ test("doesn't create alarms for enhanced Lambda Insights metrics if not enabled"
578578

579579
const lambdaFunction = new Function(stack, "Function", {
580580
functionName: "DummyLambda",
581-
runtime: Runtime.NODEJS_LATEST,
581+
runtime: determineLatestNodeRuntime(stack),
582582
code: InlineCode.fromInline("{}"),
583583
handler: "Dummy::handler",
584584
});
@@ -689,7 +689,7 @@ test("snapshot test: latency alarms with percentage of timeout with specific tim
689689

690690
const lambdaFunction = new Function(stack, "Function", {
691691
functionName: "DummyLambda",
692-
runtime: Runtime.NODEJS_18_X,
692+
runtime: determineLatestNodeRuntime(stack),
693693
code: InlineCode.fromInline("{}"),
694694
handler: "Dummy::handler",
695695
timeout: Duration.seconds(100),

0 commit comments

Comments
 (0)