Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
lambda-node-runtime
Advanced tools
The module allows you to run your JavaScript code on any Node.js version in AWS Lambda.
AWS Lambda rarely updates Node.js version, in fact AWS Lambda Node.js version problem looks similar to one Babel tries to solve for JS versions. This module enables you to use latest Node.js version with latest features and bug/security fixes.
Add module to your AWS Lambda Node.js project:
npm install lambda-node-runtime -S
Write a module that holds AWS Lambda handler:
module.exports.handler = async (event, context) => {
// Your code
}
or
module.exports.handler = (event, context, callback) => {
// Your code
}
Reference your handler using AWS Lambda Environment Variable
LAMBDA_NODE_HANDLER=index.handler
Choose Node.js 6.10
AWS Lambda Runtime, increase Timeout to at least 4 seconds (see Benchmarks section for more details) and set AWS Lambda Handler to expression
node_modules/lambda-node-runtime/index.handler
Optionally set desired Node.js version in package.json
(default is latest LTS version 8.x (Carbon))
{
"name": "your-lambda-function",
"version": "1.0.0",
"lambda-node-runtime": {
"node-version": "9.8.0"
}
}
When you install lambda-node-runtime
module it downloads Node to node_modules/lambda-node-runtime/.node
dir. Therefore, when you create an AWS Lambda package it includes desired Node runtime. When AWS Lambda package is deployed and invoked, bundled Node child process starts and executes your JS code.
It is possible to run Node version of your desire because Node binary is relatively small (around 10 MB when zipped) so there is plenty of space left for code (AWS Lambda package size restriction is 50 MB).
Also Node is fast to start so the latency between when you invoke AWS Lambda Function and when it actually starts running the code is lower.
Please note that latency is there because new Node.js child process must be started. However, Node.js child process is reused in warm AWS Lambda Function meaning only cold start is slower.
This aim of this section is help you to understand lambda-node-runtime
module suitability for your use case.
The chart depicts execution of test AWS Lambda Function (that returns the event object passed to it)
module.exports.handler = (event, context, callback) => {
callback(null, event);
}
Both AWS Lambda Functions are allocated 128 MB of Memory.
It takes around 4 seconds for cold AWS Lambda Function to start in case of lambda-node-runtime
is used (compared to 20 milliseconds in case of plain AWS Lambda Runtime). According to this article AWS keeps the idle Lambda Function warm for up to 1 hour.
Let's hide the first run to compare subsequent runs.
Subsequent runs duration (except 2nd and 7th runs) is very similar. Please note that despite 2nd and 7th runs take relatively longer, it is only around 5 milliseconds.
The reasons why all the runs with lambda-node-runtime
take a bit longer are:
FAQs
Run any Node version on AWS Lambda
The npm package lambda-node-runtime receives a total of 20 weekly downloads. As such, lambda-node-runtime popularity was classified as not popular.
We found that lambda-node-runtime demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.