AWS Compute Blog
Node.js 14.x runtime now available in AWS Lambda
You can now develop AWS Lambda functions using the Node.js 14.x runtime. This is the current Long Term Support (LTS) version of Node.js. Start using this new version today by specifying a runtime parameter value of nodejs14.x when creating or updating functions or by using the appropriate managed runtime base image.
Language Updates
Node.js 14 is a stable release and brings several new features, including:
- Updated V8 engine
- Diagnostic reporting
- Updated Node streams
V8 engine updated To V8.1
Node.js 14.x is powered by V8 version 8.1, which is a significant upgrade from the V8 7.4 engine powering the previous Node.js 12.x. This upgrade brings performance enhancements and some notable new features:
- Nullish Coalescing
??
– A logical operator that returns its right-hand side operand when its left-hand side operand is not defined or null.const newVersion = null ?? 'this works great' ; console.log(newVersion); // expected output: "this works great" const nullishTest = 0 ?? 36; console.log(nullishTest); // expected output: 0 because 0 is not the same as null or undefined
This new operator is useful for debugging and error handling in your Lambda functions when values unexpectedly return null or undefined.
- Intl.DateTimeFormat – This feature enables numberingSystem and calendar options.
const date = new Date(Date.UTC(2021, 01, 20, 3, 23, 16, 738)); // Results below assume UTC timezone - your results may vary // Specify date formatting for language console.log(new Intl.DateTimeFormat('en-US').format(date)); // expected output: "2/20/2021"
- Intl.DisplayNames – Offers the consistent translation of region, language, and script display names.
const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' }); console.log(regionNamesInEnglish.of('US')); // expected output: "United States"
- Optional Chaining
?.
– Use this operator to access a property’s value within a chain without needing to validate each reference. This removes the requirement of checking for the existence of a deeply nested property using the && operator or lodash.get:const player = { name: 'Roxie', superpower: { value: 'flight', } }; // Using the && operator if (player && player.superpower && player.superpower.value) { // do something with player.superpower.value } // Using the ?. operator if (player?.superpower?.value) { // do something with player.superpower.value }
Diagnostic reporting
Diagnostic reporting is now a stable feature in Node.js 14. This option allows you to generate a JSON-formatted report on demand or when certain events occur. This helps to diagnose problems such as slow performance, memory leaks, unexpected errors, and more.
The following example generates a report from within a Lambda function, and outputs the results to Amazon CloudWatch for further inspection.
const report = process.report.getReport();
console.log(typeof report === 'object'); // true
// Similar to process.report.writeReport() output
console.log(JSON.stringify(report, null, 2));
See the official docs on diagnostic reporting in Node.js to learn other ways to use the command.
Updated node streams
The streams APIs has been updated to help remove ambiguity and streamline behaviours across the various parts of Node.js core.
Runtime Updates
To help keep Lambda functions secure, AWS updates Node.js 14 with all minor updates released by the Node.js community when using the zip archive format. For Lambda functions packaged as a container image, pull, rebuild and deploy the latest base image from DockerHub or Amazon ECR Public.
Deprecation schedule
AWS will be deprecating Node.js 10 according to the end of life schedule provided by the community. Node.js 10 reaches end of life on April 30, 2021. After April 30, 2021 you can no longer create a Node.js 10 Lambda function. The ability to update a function will be disabled after May 28, 2021 . More information on can be found in the runtime support policy.
You can migrate existing Node.js 12 functions to the new runtime by making any necessary changes to code for compatibility with Node.js 14, and changing the function’s runtime configuration to “nodejs14.x”. Lambda functions running on Node.js 14 will have 2 full years of support.
Amazon Linux 2
Node.js 14 managed runtime, like Node.js 12, Java 11, and Python 3.8, is based on an Amazon Linux 2 execution environment. Amazon Linux 2 provides a secure, stable, and high-performance execution environment to develop and run cloud and enterprise applications.
Next steps
Get started building with Node.js 14 today by specifying a runtime parameter value of nodejs14.x when creating your Lambda functions using the zip archive packaging format. You can also build Lambda functions in Node.js 14 by deploying your function code as a container image using the Node.js 14 AWS base image for Lambda. You can read about the Node.js programming model in the AWS Lambda documentation to learn more about writing functions in Node.js 14.
For existing Node.js functions, migrate to the new runtime by changing the function’s runtime configuration to nodejs14.x
Happy coding with Node.js 14!