aws-lambda-node-runtime
v0.1.0
Published
AWS Lambda runtime API implemented in Node.js.
Downloads
19
Readme
AWS Lambda NodeJS Custom Runtime
AWS Lambda runtime API implemented in Node.js.
This library can be used to implement
- a custom runtime Lambda layer for any Node.js version
- a container runtime with Node.js as the execution environment
- to test your Node.js lambda functions locally
Goals
- Provide a robust custom Node.js execution environment
- Make sure that it's compatible with the official
node12.xandnode14.xenvironments
How to install?
npm install aws-lambda-node-runtime --saveHow to use it?
The following examples assume that
- your lambda function code is in the
/var/taskfolder. - There's
/var/task/index.jsfile that exports the Lambdahandlerfunction
You need to set the following environment variables
export LAMBDA_TASK_ROOT=/var/task
export AWS_LAMBDA_FUNCTION_NAME=my-function-name
export AWS_LAMBDA_FUNCTION_VERSION=v1
export AWS_LAMBDA_FUNCTION_MEMORY_SIZE=128
export AWS_LAMBDA_LOG_GROUP_NAME=test-log-group-name
export AWS_LAMBDA_LOG_STREAM_NAME=test-log-stream-nameUse it from your JS code
const runtime = require('aws-lambda-node-runtime');
const done = (err) => {
if (err) {
console.warn('Runtime exiting due to an error', err)
}
}
process.env._HANDLER = 'index.handler';
console.warn('Runtime starting...')
runtime(done);Execute it directly from a script or command line
# The follow command assumes that there's /path/to/your/app/index.js file that exports the `handler` functions
npx aws-lambda-node-runtime index.handlerIntegration tests
Execute the Lambda API test server
npx ts-node runtime-api/serverIn another terminal execute the runtime with hello.js as the Lambda source
npx ts-node integration/test