typescript 在aws Lambda上检测DataDog,找不到我的函数

cyvaqqii  于 2022-12-24  发布在  TypeScript
关注(0)|答案(1)|浏览(144)

在Typescript Lambda函数中执行Datadog Instrumenting时遇到问题
这是我的文件夹结构:

这是我的Docker文件

FROM public.ecr.aws/lambda/nodejs:16 AS builder

WORKDIR /usr/app
COPY . ./
RUN npm install
RUN npm run build

FROM public.ecr.aws/lambda/nodejs:16

COPY --from=public.ecr.aws/datadog/lambda-extension:latest /opt/extensions/ /opt/extensions

COPY --from=builder /usr/app/build ./
COPY --from=builder /usr/app/package.json ./

RUN mkdir -p ./output
RUN npm install --omit=dev

ENV DD_LAMBDA_HANDLER ="app.handler"

RUN rm node_modules/datadog-lambda-js/dist/handler.js
CMD ["node_modules/datadog-lambda-js/dist/handler.handler"]

另外,这些是我对package.json的依赖项

所有的Docker构建和部署都运行良好,但是在我尝试调用我的函数时,我收到了一个与找不到我的app.handler函数有关的错误。

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '=app'\nRequire stack:\n- /var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js\n- /var/task/node_modules/datadog-lambda-js/dist/runtime/index.js","trace":["Runtime.ImportModuleError: Error: Cannot find module '=app'","Require stack:","- /var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js","- /var/task/node_modules/datadog-lambda-js/dist/runtime/index.js","    at ImportModuleError.ExtendedError [as constructor] (/var/task/node_modules/datadog-lambda-js/dist/runtime/errors.js:113:28)","    at new ImportModuleError (/var/task/node_modules/datadog-lambda-js/dist/runtime/errors.js:123:42)","    at /var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js:273:31","    at step (/var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js:43:23)","    at Object.throw (/var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js:24:53)","    at rejected (/var/task/node_modules/datadog-lambda-js/dist/runtime/user-function.js:16:65)"]}%

当然,当我在docker文件中更改CMD时:

CMD ["app.handler"]

一切都很完美
你知道我在配置中遗漏了什么吗?

py49o6xq

py49o6xq1#

我使用以下实现选项使其工作:
https://docs.datadoghq.com/serverless/guide/handler_wrapper/
我基本上是用datadog Package 处理程序函数,并继续使用我的app.handler作为Dockerfile中的入口点

CMD ["app.handler"]

这里是如何看我的app.ts文件:

相关问题