Skip to content

Commit ca42461

Browse files
authored
chore(lambda-nodejs): update default runtime (#13664)
If the installed node version is >= 14, use Node.js 14.x. Otherwise, use Node.js 12.x. This removes a default on the deprecated Node.js 10.x runtime. BREAKING CHANGE: the default runtime of a `NodejsFunction` is now Node.js 14.x if the environment from which it is deployed uses Node.js >= 14 and Node.js 12.x otherwise. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent a872e67 commit ca42461

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export interface NodejsFunctionProps extends lambda.FunctionOptions {
3434
* The runtime environment. Only runtimes of the Node.js family are
3535
* supported.
3636
*
37-
* @default - `NODEJS_12_X` if `process.versions.node` >= '12.0.0',
38-
* `NODEJS_10_X` otherwise.
37+
* @default - `NODEJS_14_X` if `process.versions.node` >= '14.0.0',
38+
* `NODEJS_12_X` otherwise.
3939
*/
4040
readonly runtime?: lambda.Runtime;
4141

@@ -105,9 +105,9 @@ export class NodejsFunction extends lambda.Function {
105105
// Entry and defaults
106106
const entry = path.resolve(findEntry(id, props.entry));
107107
const handler = props.handler ?? 'handler';
108-
const defaultRunTime = nodeMajorVersion() >= 12
109-
? lambda.Runtime.NODEJS_12_X
110-
: lambda.Runtime.NODEJS_10_X;
108+
const defaultRunTime = nodeMajorVersion() >= 14
109+
? lambda.Runtime.NODEJS_14_X
110+
: lambda.Runtime.NODEJS_12_X;
111111
const runtime = props.runtime ?? defaultRunTime;
112112

113113
super(scope, id, {

packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Runtime } from '@aws-cdk/aws-lambda';
77
import { Stack } from '@aws-cdk/core';
88
import { NodejsFunction } from '../lib';
99
import { Bundling } from '../lib/bundling';
10+
import { nodeMajorVersion } from '../lib/util';
1011

1112
jest.mock('../lib/bundling', () => {
1213
return {
@@ -35,8 +36,13 @@ test('NodejsFunction with .ts handler', () => {
3536
entry: expect.stringContaining('function.test.handler1.ts'), // Automatically finds .ts handler file
3637
}));
3738

39+
const runtime = nodeMajorVersion() >= 14
40+
? Runtime.NODEJS_14_X
41+
: Runtime.NODEJS_12_X;
42+
3843
expect(stack).toHaveResource('AWS::Lambda::Function', {
3944
Handler: 'index.handler',
45+
Runtime: runtime.name,
4046
});
4147
});
4248

0 commit comments

Comments
 (0)