Version 6.82.0 breaks AWS RIC support
cRicateau opened this issue · 1 comments
Expected Behavior
dd-lambda-js works with container-based lambdas that are build using AWS Lambda NodeJS Runtime Interface Client
. AWS lambda RIC allows to create custom docker images to use them for lambda, which is useful when you need to create a lambda based on your own docker image.
Actual Behavior
Since version 6.82.0
(6.81.0
is fine), the file node_modules/datadog-lambda-js/dist/handler.js
is not bundled anymore in the npm package. However AWS lambda ric doesn't seem to work without it, it throws an error Cannot find module 'handler'
.
The code that throws is that one https://github.com/aws/aws-lambda-nodejs-runtime-interface-client/blob/main/src/utils/UserFunction.ts#L106
Because of this, all custom container based lambdas cannot be instrumented with version > 6.81.0.
So the problem is not really about the code itself, but the way it integrates with AWS RIC.
Steps to Reproduce the Problem
- Create a dummy lambda with AWS RIC => Follow the AWS RIC tuto (see doc in https://www.npmjs.com/package/aws-lambda-ric)
- Add datadog docker layer + dd-lambda-js@6.82.0 => Follow the datadog tuto https://docs.datadoghq.com/serverless/installation/nodejs/?tab=containerimage
- Build the container image
- Run the image (I recommend adding AWS RIE cf https://docs.aws.amazon.com/gb_gb/lambda/latest/dg/images-test.html) (warning about this that will happen on version 6.81.0 aws/aws-lambda-runtime-interface-emulator#65, for version 6.82.0 the problem doesn't happen since it throws before)
- See error by calling running the lambda
curl --request POST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' --header 'Content-Type: application/json'
if you have done step 4
Specifications
- Datadog Lambda Layer version: 6.82.0
- Node version: 16.16
Stacktrace
From AWS lambda RIC:
{
"errorType":"Runtime.ImportModuleError",
"errorMessage":"Error: Cannot find module 'handler'\nRequire stack:\n- /function/node_modules/aws-lambda-ric/lib/utils/UserFunction.js\n
}
Hi @cRicateau - thanks for reaching out.
I'm unsure why that file was removed only in 6.82 but not earlier, as it was removed from this repository in 6.76.
You could probably copy it in your docker image as a workaround:
RUN cp node_modules/datadog-lambda-js/dist/handler.cjs node_modules/datadog-lambda-js/dist/handler.js
But I can re-add it and cut a new release. Thanks!