aws / aws-lambda-nodejs-runtime-interface-client

Apache License 2.0
180 stars 56 forks source link

Allow passing HandlerFunction to `run` function directly #20

Closed Ugzuzg closed 2 years ago

Ugzuzg commented 3 years ago

It would be useful for us to be able to pass the handler function directly to the run export when using it programmatically, as we want to have our own RIC, which loads a handler that doesn't need to know about being inside lambda.

import { run } from 'aws-lambda-ric';

import loadCustomHandler from './some-path';

const customHandler = loadCustomHandler(...);

const handler = async (event: Event, context: unknown): Promise<void> => {
  const parsedPayload = ...;
  await customHandler(parsedPayload);
}

run(handler);
thekiwi commented 3 years ago

Hi @carlzogh, it seems you are the primary contributor on this repo. Are we able to get some feedback on this PR? We have some internal PRs that are blocked waiting on whether this PR will be merged or not. Thanks in advance!

carlzogh commented 3 years ago

Thanks for your contribution @Ugzuzg!

The approach looks good to me, this would also enable the NodeJS RIC to be run similarly to the GoLang RIC by passing a static reference to a function handler.

Would you be able to add test coverage for isHandlerFunction() and the new invocation mode as part of this PR as well?

Ugzuzg commented 3 years ago

@carlzogh, I have added the tests as requested. Also, modified the signature of the run function to match GoLang's RIC (no appRoot required when passing the handler as a function).

Ugzuzg commented 3 years ago

@carlzogh, forgot to run make format before pushing. Should be better now. Can you please approve the workflow again?

Ugzuzg commented 3 years ago

@carlzogh, rebased on top of the latest changes from main branch. Can you please review?

thekiwi commented 3 years ago

@carlzogh any update on this? thanks in advance!

thekiwi commented 2 years ago

Hey @zsombor-balogh - many thanks for reviewing and merging! Are you able to release a new version of the library which includes the change, so we can start using it?