lambda-node-runtime
Advanced tools
Comparing version
{ | ||
"name": "lambda-node-runtime", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"description": "Run any Node version on AWS Lambda", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,4 +16,5 @@ # Lambda Node Runtime | ||
### Usage | ||
Write a module that holds AWS Lambda handler: | ||
Write a module that holds AWS Lambda handler (i.e.: `index.js`): | ||
```js | ||
// index.js | ||
module.exports.handler = async (event, context) => { | ||
@@ -25,2 +26,3 @@ // Your code | ||
```js | ||
// index.js | ||
module.exports.handler = (event, context, callback) => { | ||
@@ -30,11 +32,11 @@ // Your code | ||
``` | ||
Reference your handler using AWS Lambda Environment Variable | ||
Reference your handler using AWS Lambda Environment Variable (i.e.: `index.js`): | ||
``` | ||
LAMBDA_NODE_HANDLER=index.handler | ||
``` | ||
Choose `Node.js 6.10` AWS Lambda Runtime, increase Timeout to at least 4 seconds (see [Benchmarks](#benchmarks) section for more details) and set AWS Lambda Handler to expression | ||
Choose `Node.js 6.10` AWS Lambda Runtime, increase Timeout to at least 4 seconds (see [Benchmarks](#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)) | ||
Optionally set desired Node.js version in `package.json` (default is latest LTS version 8.x (Carbon)): | ||
```json | ||
@@ -50,2 +52,16 @@ { | ||
### Serverless support | ||
Example `serverless.yml` configuration: | ||
```yml | ||
functions: | ||
yourLambdaFunction: | ||
handler: node_modules/lambda-node-runtime/index.handler | ||
runtime: nodejs6.10 | ||
timeout: 4 # Cold start might take up to 4 seconds. | ||
environment: | ||
LAMBDA_NODE_HANDLER: index.handler # when handler method `handler` is in `index.js` module | ||
``` | ||
Please note that when running `serverless invoke local` command, development Node.js version is used (not the one downloaded by the module). | ||
## How it works | ||
@@ -52,0 +68,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 Function package it includes desired Node runtime. When AWS Lambda Function package is deployed and invoked, bundled Node child process starts and executes your JS code. |
@@ -1,2 +0,2 @@ | ||
const { spawn } = require('child_process'); | ||
const { spawn, fork } = require('child_process'); | ||
@@ -58,7 +58,13 @@ const errors = require('./errors'); | ||
nodeChildProcess = handleNodeChildProcess( | ||
spawn( | ||
`${__dirname}/../.node/bin/node`, | ||
[`${__dirname}/lambdaFunctionInvoker`], | ||
{ stdio: [process.stdin, process.stdout, process.stderr, 'ipc'] } | ||
), | ||
process.env.IS_LOCAL | ||
? fork( | ||
`${__dirname}/lambdaFunctionInvoker`, | ||
[], | ||
{ stdio: [process.stdin, process.stdout, process.stderr, 'ipc'] } | ||
) | ||
: spawn( | ||
`${__dirname}/../.node/bin/node`, | ||
[`${__dirname}/lambdaFunctionInvoker`], | ||
{ stdio: [process.stdin, process.stdout, process.stderr, 'ipc'] } | ||
), | ||
event, | ||
@@ -65,0 +71,0 @@ context, |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
63219
1.23%188
3.3%99
19.28%11
10%