So you have AWS Lambda in production, using one of Node 14 or 16 versions, and you want to upgrade to the new Node@18 Runtimes?
We want readers to know what they have to do when upgrading their AWS Lambda to the Node@18 runtime via a checklist.
- Upgrade your local NodeJS runtime to version 18 either by directly downloading from nodejs.org, or using
nvm. As at the time of writing this, node
18.14.2is the LTS version.
npm installto get the new version of
- Add an
enginesfield to the
package.jsonto prompt when an unsupported node version is used to access the project.
- Update your AWS Lambda config to use the
nodejs18.xruntime. If you use
cloudformation, this means changing to
- Update your CI/CD pipelines to build with node version
- If you use Webpack, I’ve found webpack
5.75works great for building project written for node@18.
- If your project uses aws-sdk v2, you will want to consider that the AWS lambda
nodejs18.xruntime comes built-in with version
3.188.0of the aws-sdk, which is v3, so you need to make a decision about your projects. Don’t worry, I’ve got you.
Upgrade aws-sdk to V3
If you upgrade your aws-sdk from v2 to v3, then you can take advantage of using the exact
3.188.0 version of the
@aws-sdk/* packages built-in with the AWS Lambda
This means that you can bundle your code to not include the
@aws-sdk/* packages with webpack externals or equivalent in other bundlers, keeping your bundle size small, which has its advantages.
However, if you must use a higher sdk version than the built-in
3.188.0 version, then you will want to include your sdk code in your bundle, which will increase your bundle size, and you may run into bundling errors such as it not being able to resolve the
aws-crt module, which can be fixed by installing the
Staying with aws-sdk V2
If you stay with the v2 of the aws-sdk, then you will have to bundle it with your code. This will increase your bundle size.
End-to-end test everything
So you’ve successfully upgraded your AWS Lambda runtime to
nodejs18.x , and you have successfully deployed it to the cloud. Now, you need to test everything, to be sure nothing is broken.
Thanks for reading this. If there are steps you have found that I have not included in this article, please let me know the comments.
Have fun, coding!