AWS just released node 8.10 runtime for lambdas, check out those links:
- Official AWS post: https://aws.amazon.com/blogs/compute/node-js-8-10-runtime-now-available-in-aws-lambda/
- SLS blog: https://serverless.com/blog/aws-lambda-node-8-support-what-changes-serverless-developers/
Note that Lambda@Edge didn’t get the update. See AWS Node 8.10 runtime for Lambdas! - Migration guide
This is awesome and all new node.js projects should use node 8.10 right away, you just need to change the
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
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
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]
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 https://stackoverflow.com/questions/44985913/nodejs-8-import-module-require-or-import 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
importbabel feature), then just use v8.10 locally, recompile node modules, update the
serverless.ymland use the
runtime: nodejs8.10and 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
requireand 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.
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.