Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add context overwrite option #240

Merged
merged 2 commits into from
Apr 13, 2024
Merged

Conversation

nazoking
Copy link
Contributor

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.

@tfrancois
Copy link

This should be please added to the README file and/or documentation - I only came across this by accident. Thanks!

@gpotter2 gpotter2 merged commit 53814cb into ashiina:develop Apr 13, 2024
7 checks passed
@gpotter2
Copy link
Collaborator

Thanks for the PR & sorry for the delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants