============
Lambda-local lets you test Amazon Lambda functions on your local machine with sample event data.
The context of the Lambda function is already loaded so you do not have to worry about it.
You can pass any event JSON object as you please.
You can use Lambda-local as a command line tool.
npm install -g lambda-local# Usage
lambda-local -l index.js -h handler -e event-samples/s3-put.js- -l, --lambda-path (required) Specify Lambda function file name.
- -e, --event-path (required) Specify event data file name.
- -h, --handler (optional) Lambda function handler name. Default is "handler".
- -t, --timeout (optional) Seconds until lambda function timeout. Default is 3 seconds.
- -n, --no-force-callback (optional) Force the function to stop after having called the handler function even if context.done/succeed/fail was not called.
- -p, --profile (optional) Read the AWS profile to get the credentials from file name.
- -p, --profile-path (optional) Read the specified AWS credentials file.
Event sample data are placed in event-samples folder - feel free to use the files in here, or create your own event data.
Event data are just JSON objects exported:
// Sample event data
module.exports = {
foo: "bar"
};The context object has been directly extracted from the source visible when running an actual Lambda function on AWS.
They may change the internals of this object, and Lambda-local does not guarantee that this will always be up-to-date with the actual context object.
Since the Amazon Lambda can load the AWS-SDK npm without installation, Lambda-local has also packaged AWS-SDK in its dependencies. If you want to use this, please use the "-p" option with the aws credentials file. More infos here: http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html#cli-config-files
You can also use Lambda local directly in a script. For instance, it is interesting in a mocha test suite in combination with istanbull in order to get test coverage.
const lambdaLocal = require('lambda-local');
var jsonPayload = {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3'
}
lambdaLocal.execute({
event: jsonPayload,
lambdaPath: path.join(__dirname, 'path/to/index.js'),
profilePath: '~/.aws/credentials',
profileName: 'default',
timeoutMs: 3000,
callback: function(err, data) {
if (err) {
console.log(err);
} else {
console.log(data);
}
}
});Executes a lambda given the options object where keys are:
event- requested event as a json object,lambdaPath- requested path to the lambda function,profilePath- optional path to your AWS credentials fileprofileName- optional aws profile namelambdaHandler- optional handler name, default tohandlerregion- optional AWS region, default tous-east-1callbackWaitsForEmptyEventLoop- optional, default totruewhich forces the function to stop after having called the handler function even if context.done/succeed/fail was not called.timeoutMs- optional timeout, default to 3000 msmute- optional, allows to mute console.log calls in the lambda function, default falsecallback- optional lambda third parameter callback
This library is released under the MIT license.