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
feat: Support Ruby handlers with ::
in path definition
#1218
feat: Support Ruby handlers with ::
in path definition
#1218
Conversation
This feature would be really helpful for teams that have unit tests build around multiple lambda functions. Without handling handlers in classes, the alternative is having lambda handlers in the global scope which causes scope creep of some functions resulting in false positives and blocking issues for ruby lambdas. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @njyjn for submitting this PR. It looks good, well done 🙇
::
in path definition
Description
This enhancement adds support for Ruby handlers that have namespace resolution operators (
::
) in their path definition, e.g.handler: 'src/lambdas/examples/hello.Hello::Handler.process'
, etc. This was officially mentioned in the AWS documentation (see below). Logic was preserved for existing scenarios (without::
) to reduce the risk of regression.Without this enhancement, the following error message is triggered when the handler is invoked
This seems to be because the handler paths and names are not being split correctly. For such Ruby handlers, the
name
should have the resolution operator instead of thepath
. Support for this already seems to be built-inserverless-offline/src/lambda/handler-runner/ruby-runner/invoke.rb
Lines 75 to 78 in d319174
Motivation and Context
AWS officially demonstrates the use of handler methods within modules and classes. The specific example given is
where the handler setting is
source.LambdaFunctions::Handler.process
. Since this is the entry point for many developers, it would be great if it is supported byserverless-offline
.For projects that implement a large number of handlers, it would be optimal to not pollute the Kernel private_method namespace if such handlers can be encapsulated into their own modules and classes.
Resolves #1031
How Has This Been Tested?
Unit tests were added in 4a6d0dc to validate this enhancement, as well as the original functionality that was left in tact.
In addition to the additional unit tests, I was able to use
serverless-offline
for Ruby handlers with and without namespace separatorsBuilt locally using package.json and compiled used Babel per the contribution guide.
Please let me know if you have any questions or if there is something I can improve on. Thanks!
Edit: Added more details on the current way serverless-offline is failing to invoke such handlers. Clarified that as long as the path string contains
::
, the enhancement will take effect.Screenshots (if appropriate):