lambda-local
lambda-local copied to clipboard
add context overwrite option
My use case was that I wanted the "awsRequestId" to be something I specified. In this issue #225, the proposer seems to want to change the function name to any name. In either case, you can configure it using this additional option.
The added test case becomes a sample.
lambdalocal.execute({
event: require(path.join(__dirname, "./events/test-event.js")),
lambdaPath: path.join(__dirname, "./functs/test-func.js"),
lambdaHandler: functionName,
contextOverwrite: function (ctx){
ctx.awsRequestId = "test id";
ctx.functionName = "test function";
},
callback: function (err, done) {
assert.equal(done.result, "testvar");
assert.equal(done.context.awsRequestId, "test id");
assert.equal(done.context.functionName, "test function");
cb();
}
});
Specify a function in the optional contextOverwrite
passed to the execute
method. That function receives the created context. You can modify the context inside the function.
If you modify context.done
etc., it is expected that it will not work as expected, but please forgive this as it is the developer's own responsibility.
This should be please added to the README file and/or documentation - I only came across this by accident. Thanks!
Thanks for the PR & sorry for the delay.