VSCode AWS Sam(node12.x 图片)TypeScript 调试器未到达断点

VSCode AWS Sam (node12.x image) TypeScript debugger not reaching breakpoints

我正在尝试让 vscode 调试器使用 AWS Sam 生成的应用程序,但使用 TypeScript。

所以在我添加 TypeScript 之前,调试器工作正常,我可以毫无问题地到达断点。 当我添加 TypeScript 时,我不得不更改文件夹结构,通过添加 src 和 dist 文件夹,所以目前我的文件结构是这样的:

根据 AWS 文档(第 58 页):https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/aws-tookit-vscode-ug.pdf 我认为它与 launch.json 文件中的 pathMappings 有关,但我似乎无法弄清楚正确的路径是什么。这是我当前的 launch.json 文件:

 {
    "configurations": [
        
        {
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "puppeteer-pdfMerger:HelloWorldFunction",
            "invokeTarget": {
                "target": "template",
                "templatePath": "puppeteer-pdfMerger/template.yaml",
                "logicalId": "HelloWorldFunction"
            },
            "lambda": {
                "runtime": "nodejs12.x",
                "payload": {},
                "environmentVariables": {},
                "pathMappings": [{
                    "localRoot": "${workspaceFolder}/puppeteer-pdfMerger/hello-world/dist/HelloWorldFunction",
                    "remoteRoot": "/var/task/dist"
                }]
            }
        }
}

我会注意到,当运行此配置时,容器化 Lambda 运行良好,只是断点不起作用。

最后我设法让断点起作用。

最终对我有用的是将 Dockerfile 更改为:

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

COPY dist/*.js package.json ./

RUN npm install

# Command can be overwritten by providing a different command in the template directly.
CMD ["app.lambdaHandler"]

launch.json 配置如下:

{
            "type": "aws-sam",
            "request": "direct-invoke",
            "name": "puppeteer-pdfMerger:PdfGeneratorAndMergerFunction TemplateTarget",
            "invokeTarget": {
                "target": "template",
                "templatePath": "puppeteer-pdfMerger/template.yaml",
                "logicalId": "PdfGeneratorAndMergerFunction"
            },
            "lambda": {
                "runtime": "nodejs12.x",
                "payload": {},
                "environmentVariables": {},
                "pathMappings": [
                    {
                        "localRoot": "${workspaceRoot}/puppeteer-pdfMerger/hello-world/dist",
                        "remoteRoot": "/var/task"
                    }
                ]
            }
        }