floydspace/serverless-esbuild

Overriding the keyword used to get the handler in the lambda function defintion

Opened this issue · 1 comments

Is your feature request related to a problem? Please describe.
We are trying to setup Datadog in our serverless project. We are also using serverless-esbuild. An issue we are encountering is in src/helper.ts on line 68:

const { handler } = func;

The keyword handler is used to get the entrypoint to give to esbuild. However with Datadog, this handler is overidden by /opt/nodejs/node_modules/datadog-lambda-js/handler.handler and the real handler is located in the environment:

DD_LAMBDA_HANDLER: 'handler.main'

This is throwing us the following error:

Error: Compilation failed for function alias XX. Please ensure you have an index file with ext .ts or .js, or have a path listed as main key in package.json
    at /Users/XX/XX/XX/node_modules/serverless-esbuild/src/helper.ts:98:13

Describe the solution you'd like
We would like serverless-esbuild to work with Datadog, we can see the following idea:

Allow an other keyword to be used: (could be hardcoded or defined in the custom part of the serverless file?)

{
  handler: '/opt/nodejs/node_modules/datadog-lambda-js/handler.handler',
  esbuildEntrypoint: `${pathResolver(__dirname)}/handler.main`,
}
const { handler, esbuildEntrypoint } = func;
const entryPoint = esbuildEntrypoint || handler;

Describe alternatives you've considered
Maybe there is already a way to achieve what we are trying to do here? Did we miss it?

Additional context
If indeed there is no way to achieve what we are doing, we would be pleased to work on a pull request if you think this could be useful for others

@floydspace What do you think?