serverless-esbuild icon indicating copy to clipboard operation
serverless-esbuild copied to clipboard

Feature request : being able to customize handler resolution

Open wimpheling opened this issue 4 years ago • 3 comments

I've been trying to use your plugin but my setup involves Instana (a log analyzer vendor). The @instana/serverless module works this way :

  • You must add an instana layer that provides the libraries
  • You change the handler to an instana handler provided by the layer
  • You provide the 'real' handler to the instana layer in an env variable.

So the lambda looks like this :

Login:
 handler: instana-aws-lambda-auto-wrap.handler
 environment:
   LAMBDA_HANDLER: src/handlers/Login.handler
 layers:
   - arn:aws:lambda:eu-west-1:410797082306:layer:instana-nodejs:38

When using serverless-esbuild this breaks handler resolution. I've been able to make it work by forking the module and replacing this line : https://github.com/floydspace/serverless-esbuild/blob/65b7431aca4bfe5b8f85bd1aecf8d6c1b9fc050b/src/helper.ts#L36-L37

with

  return Object.values(functions)
        .map(fn => (fn.environment && fn.environment.LAMBDA_HANDLER) || fn.handler)

Of course, this is very specific, so I wonder if you could add a way of providing this in the configuration or overriding the extractFileNames function, as you already provide a special behavior for the google provider.

If you're ok or have an idea about how it should be implemented, I may be able to submit a PR.

Thanks

wimpheling avatar Feb 23 '21 10:02 wimpheling

Hi @wimpheling, thank you for the request, we will consider this if we get more requests. For now, I recommend using patch-package, it's a nice package to keep your patches to node_modules shared. so you do not have to make a fork or whatever.

floydspace avatar Feb 26 '21 14:02 floydspace

@wimpheling did @floydspace's recommendation worked for you ? Can we close this ?

olup avatar Jun 28 '21 10:06 olup

Support for the Instana lambda layer would be a great enhancement for us. Serverless-Webpack allows this now by letting you set a different entrypoint for each lambda function.

spamalot22 avatar May 21 '24 12:05 spamalot22