typescript - 在 AWS Lambda 和 AWS Cloudwatch 中使用 Typescript 源映射

标签 typescript aws-lambda amazon-cloudwatch

我正在使用 AWS Lambdas 和由 构建的 Typescript ESBuild
ESBuild 将所有必要的代码聚合在一个 index.js 构建文件中,这使得冷启动非常快,并确保不会发送不必要的代码。
它还可以生成源 map .
你知道我怎么做 Cloudwatch 注意源 map 为了获得与我的实际源代码而不是构建相关的堆栈跟踪?

最佳答案

我找到了答案 here :NodeJS 支持 sourcemaps,Lambda 支持节点选项。
在 Typescript 上生成源映射,然后将此环境变量添加到 lambda 中:

NODE_OPTIONS=--enable-source-maps
现在,当记录堆栈跟踪时,它指向原始文件和行
{
  "errorType": "Error",
  "errorMessage": "Missing process.env.TABLE_EVENT",
  "trace": [
    "Error: Missing process.env.TABLE_EVENT",
    "    at /var/task/index.js:12496:11",
    "        -> /backend/service/userService/lib/dynamodb.js:6:9",
    "    at /var/task/index.js:4:5",
    "    at /var/task/index.js:16979:18",
    "        -> /backend/service/userService/lib/handlers/publishReminders.js:4:26",
    "    at /var/task/index.js:4:5",
    "    at /var/task/index.js:17121:33",
    "        -> /backend/service/userService/lib/handlers/index.js:1:43",
    "    at /var/task/index.js:4:5",
    "    at Object.<anonymous> (/var/task/index.js:17136:16)",
    "        -> /backend/service/userService/lib/index.js:16:26",
    "    at Module._compile (internal/modules/cjs/loader.js:999:30)",
    "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)",
    "    at Module.load (internal/modules/cjs/loader.js:863:32)"
  ]
}

关于typescript - 在 AWS Lambda 和 AWS Cloudwatch 中使用 Typescript 源映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66204823/

相关文章:

typescript - VSC 中的 ESLint 不适用于 .ts 和 .tsx 文件

amazon-web-services - IAM 用户上 lambda ListFunctions 的 AWS AccessDeniedException

amazon-web-services - 如何在 aws lambda 中隐藏 sql 连接字符串?

kubernetes - 使用 AWS Container Insights 监控 Kubernetes CronJob 完成

typescript - 如何在没有 tsconfig.json 文件的情况下运行 typeScript 代码?

typescript - Webpack typescript 热重载未编译

reactjs - 使用 Material UI makeStyles 时输入的 props

javascript - 等待 lambda 初始化

java - 为什么与 jclouds 一起使用的 CloudWatch API getMetricStatisticsInRegion 会抛出 UndeclaredThrowableException?

amazon-web-services - 添加堆栈时自动从堆栈转发 CW 日志