Skip to content

Commit

Permalink
chore(lambda-nodejs): update default runtime (#13664)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
jogold authored Mar 18, 2021
1 parent a872e67 commit ca42461
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ export interface NodejsFunctionProps extends lambda.FunctionOptions {
* The runtime environment. Only runtimes of the Node.js family are
* supported.
*
* @default - `NODEJS_12_X` if `process.versions.node` >= '12.0.0',
* `NODEJS_10_X` otherwise.
* @default - `NODEJS_14_X` if `process.versions.node` >= '14.0.0',
* `NODEJS_12_X` otherwise.
*/
readonly runtime?: lambda.Runtime;

Expand Down Expand Up @@ -105,9 +105,9 @@ export class NodejsFunction extends lambda.Function {
// Entry and defaults
const entry = path.resolve(findEntry(id, props.entry));
const handler = props.handler ?? 'handler';
const defaultRunTime = nodeMajorVersion() >= 12
? lambda.Runtime.NODEJS_12_X
: lambda.Runtime.NODEJS_10_X;
const defaultRunTime = nodeMajorVersion() >= 14
? lambda.Runtime.NODEJS_14_X
: lambda.Runtime.NODEJS_12_X;
const runtime = props.runtime ?? defaultRunTime;

super(scope, id, {
Expand Down
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Runtime } from '@aws-cdk/aws-lambda';
import { Stack } from '@aws-cdk/core';
import { NodejsFunction } from '../lib';
import { Bundling } from '../lib/bundling';
import { nodeMajorVersion } from '../lib/util';

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

const runtime = nodeMajorVersion() >= 14
? Runtime.NODEJS_14_X
: Runtime.NODEJS_12_X;

expect(stack).toHaveResource('AWS::Lambda::Function', {
Handler: 'index.handler',
Runtime: runtime.name,
});
});

Expand Down

0 comments on commit ca42461

Please sign in to comment.