0

Im trying to get vscode debugger to work with an application generated with AWS Sam, but with TypeScript.

So before I added TypeScript, the debugger worked fine, I could reach the breakpoints without issue. When I added TypeScript, I had to change to folder structure, by adding a src and dist folder, so currently my file structure is like this:

enter image description here

According to AWS documentation (page 58): https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/aws-tookit-vscode-ug.pdf I think it has to do with the pathMappings in the launch.json file, but I can't seem to figure out what would the correct path. This is my current launch.json file:

 {
    "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"
                }]
            }
        }
}

I will note that when running this configuration the containerized Lambda runs fine, it's just the breakpoints are not working.

RRC
  • 70
  • 2
  • 9
  • Remember that your Typescript compiles to Javascript, and SAM runs that Javascript locally. You must debug the Javascript file. – Michael Lee Dec 09 '20 at 03:23
  • yep you are correct @MichaelLee but that's what I'm trying to do. You can see the generated js file is under dis folder and that's where I'm trying to point to under the pathMappings. I added breakpoints to both the ts file and js file, but none are being reached. – RRC Dec 10 '20 at 11:05

1 Answers1

0

I managed to get the breakpoints to work in the end.

What ended up working for me was changing the Dockerfile to:

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"]

And having the launch.json config as follows:

{
            "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"
                    }
                ]
            }
        }
RRC
  • 70
  • 2
  • 9