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
- Provide a robust custom Node.js execution environment
- Make sure that it's compatible with the official
node12.xandnode14.xenvironments
npm install aws-lambda-node-runtime --saveThe 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-nameconst 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);# 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.handlerExecute 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