-
Notifications
You must be signed in to change notification settings - Fork 4k
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
aws-lambda-nodejs: Overrides of handler
always get prefixed with index.
#24403
Comments
This sounds like an interesting use case. Looks like you are planning to bundle your nodejs app with |
Oh yeah I already use this in a few internal projects (I made a patch the Lambda Web Adapter to add gzip support recently) where we use But in other projects where we're using an external adapter that wants us to set the |
@huntharo This is awesome! If you have capacity, we'd love to review your PR when it's ready and we appreciate more feedback around this use case from the community. Thank you! |
@pahud - It looks like the PR #24406 is ready in that all the tests are passing... but let me know if you like the approach or not. I don't think there is a case where using a I'm I am correct then it means no one can be using a Is there a case where a handler name without a filename can have a dot for a Node.js app? Such as, can you have the handler be a static method of a class and use Also... please check the documentation. There was not much discussion around the |
Hi @huntharo Thank you for your PR contribution. I've seen the CI passed with integ testing update, which is great. I will not be able to review your PR but the CDK core team maintainers will. Feel free to discuss more details with the reviewer in the PR comments. Good luck! |
…reaks custom non-`index` handler settings used by layers (#24406) Using `lambda-nodejs` makes it very easy to bundle functions with `esbuild`, but the code currently *always* prefixes the `handler` value with `index.`, which makes it impossible to use some lambda extensions together with this module as they require setting `handler` to specific values and the `index.` prefixing breaks the ability to set the handler to those values. This PR avoids adding the `index.` prefix if the specified `handler` value contains a `.` already. Closes #24403 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
…reaks custom non-`index` handler settings used by layers (aws#24406) Using `lambda-nodejs` makes it very easy to bundle functions with `esbuild`, but the code currently *always* prefixes the `handler` value with `index.`, which makes it impossible to use some lambda extensions together with this module as they require setting `handler` to specific values and the `index.` prefixing breaks the ability to set the handler to those values. This PR avoids adding the `index.` prefix if the specified `handler` value contains a `.` already. Closes aws#24403 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Describe the bug
Some lambda extensions require changing the handler to a specific value but
aws-lambda-nodejs
always prefixes this withindex.
, breaking the intended values.For example, the AWS Lambda Web Adapter requires
run.sh
:https://github.com/awslabs/aws-lambda-web-adapter#lambda-functions-packaged-as-zip-package-for-aws-managed-runtimes
For example, an extension from NewRelic requires
newrelic-lambda-wrapper.handler
:https://docs.newrelic.com/docs/serverless-function-monitoring/aws-lambda-monitoring/enable-lambda-monitoring/instrument-your-own/
Expected Behavior
If a handler is set to a value with a
.
in it then theindex.
prefix logic should not apply.Current Behavior
Values like
run.sh
are turned intoindex.run.sh
Reproduction Steps
Possible Solution
I have personally been using a patch for this for 15 months that does not add the
index.
prefix if the user intentionally sets thehandler
to a value that includes a.
:The code is unchanged, essentially, even today:
aws-cdk/packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts
Line 111 in 0ebbf58
Additional Information/Context
aws-lambda-nodejs
is intended to the aneasy
button for bundling Node.js apps, and it largely performs well at that task.But if the user intentionally overrides the
handler
value then the easy button quickly becomes more difficult as you either have to patch this behavior withpatch-package
after tracing it through in a debugger, or you have to remove all usage ofaws-lambda-nodejs
just so that you can set the handler and not have it get mangled. Neither of these turn out to be that easy :)CDK CLI Version
2.66.1
Framework Version
2.66.1
Node.js Version
18
OS
Mac
Language
Typescript
Language Version
n/a
Other information
I can submit a pull request if the solution is thought to be adequate.
If the solution works but needs a feature flag to be enabled I can submit it that way too. Let me know if there is an alternative approach and I'll see if I can submit it that way.
The text was updated successfully, but these errors were encountered: