AWS Node 8.10 runtime for Lambdas! - Migration guide

AWS just released node 8.10 runtime for lambdas, check out those links:

Note that Lambda@Edge didn’t get the update. See AWS Node 8.10 runtime for Lambdas! - Migration guide - #3 by TylorShin

This is awesome and all new node.js projects should use node 8.10 right away, you just need to change the provider.runtime in serverless.yml:

provider:
  name: aws
  runtime: nodejs8.10 # change this and your lambda will be deployed on a node.js 8.10 runtime

Honnestly, it’s a long-waited feature support, node 8 is awesome and we get the native rest/spread, async/await, a better speed and the new npx binary, from npm. (npx is basically a way to run local packages from the CLI without looking for them all the way to node_modules

Also, node8.10 is faster than 6.10:

Specifically: about 7% reduction in runtime and 23% reduction in render time (if you’re doing server-side rendering in your Lambda function). [Source: David Wells]

Backward compatibility

Beware that your babelified code working fine under node6.10 may not work on 8.10, if you remove babel.
For instance, you may be relying on the import feature which is a babel feature and not an ES6 feature.

There is partial support for import feature from node 8.5 but it requires to use the --experimental-modules flag. (See node.js - nodejs 8 import module - require or import? - Stack Overflow for details)

You can’t just switch to node8.10 and remove Babel if you’re using such feature. (and there may be more backward incompatibility I’m not yet aware of)

Should I use node8.10?

I asked myself the same question and we talked about it on SLS Slack, so I thought I’d make a forum topic to let you all know why and why not migrate.

The simple answer is YES, but it depends on your situation:

If you are:

  • Creating a new node.js project: Yes, you’ve got everything to gain by using the new version and avoid to setup babel (also makes “getting started” easier)

  • Upgrading an existing project: It basically depends if you’re willing to deal with the upgrade caveats, but at the very least you should upgrade to 8.10 and keep your babel configuration, also don’t forget to reinstall all your packages by using the 8.10 version locally to avoid issues. (thumb rule: always use the same node.js version locally as the one you deploy to, you’ll avoid drama, I promise)

    • If your app is sensitive/big and you don’t want to spend time migrating it (or want to keep using the import babel feature), then just use v8.10 locally, recompile node modules, update the serverless.yml and use the runtime: nodejs8.10 and deploy on AWS. This should work for any project. Additionally, you can configure Babel to optimize code for node8.10 runtime.

    • If you’re willing to spend more time and chase bugs, then you can completely remove babel/webpack (I guess most people use serverless-webpack), convert all your import to require and let us know if you’ve met additional issues.

Anyway, I’d wait a few days to see what other caveats we run into while migrating, before attempting to migrate big production apps. In any case it is strongly recommended to use a staging environment to ensure your application is still working as expected, don’t update your production app without testing it first.

Should I remove babel/webpack?

As fschmid pointed out:

With babel/webpack you have the Node version independent optimized packaging and tree-shaking, which just cannot be done with plain Node8 and packaging everything in your project root.
Removing babel/webpack might show some unexpected results.

It is true that, depending on what you use to compile/bundle/zip your app, there may be optimisations done under the hood, like those.

Also, tools like serverless-webpack do some automatic module dependencies injection that are very handy (avoid to include a dependency), so if you get rid of such tool, you’ll have to add the dependencies yourself.

Should I start using Async/Await everywhere?

You may want to play with the cool new tools at your disposal, but make sure you’ve read thoroughly this post before doing so, especially if you’ve never really used promises before.

Read Understand promises before you start using async/await | by Daniel Brain | Medium

Thanks to fschmid for providing this great resource.


Improving this post

Don’t hesitate to propose changes/updates/advices, I’ll update this blog post accordingly.

Special thanks to Gary Rutland for his help and tests against AWS 8.10 runtime and to fschmid for his feedback and advices.

4 Likes

yes, I saw it as well. Nice to follow up

For the people who are using Lambda@Edge,
It doesn’t work Lambda@Edge function with the latest stable Serverless.

The error message is below.

An error occurred: CloudFrontDistribution - The function has an invalid runtime for functions that are triggered by a CloudFront event: nodejs8.10 Expecting: nodejs6.10 Function: arn:aws:lambda:us-east-1:966390130392:function:~~~~:13 (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidLambdaFunctionAssociation; Request ID: 0d529603-37e3-11e8-bcb4-3d379f0b0c9a).

1 Like

Note:
XRAY is broken if using Node 8.10 and ASYNC/AWAIT’s without callbacks in the handler…

We just found this out yesterday when troubleshooting why things were failing through the API Gateway…

I migrated a big project today, and the time node8 uses to bunde all package is very very much faster than when using node6, it’s like 3-5 times faster, from 3-5mn to 1mn only. Performance improvement ain’t no joke.

1 Like

nodejs 8 is no longer supported on serverless framework? @Vadorequest-SL

No, AWS follows the official Node.js deprecation notices.

Gotta use v12 or v14 nowadays. Even v10 will be removed soon, it’s already deprecated.