aws-toolkit-vscode: (Rancher) SAM debug fails

Problem

I’m having trouble getting the “AWS SAM: API Gateway lambda invoke” debug config to make it to a breakpoint, using even a simple app, before throwing an error.

I set up a simple SAM application using the sam init tool. I chose the “Hello World Example” Quick Start Template using Node.js 16 with the ZIP package type. (“No” to XRay and CloudWatch.) I’m running Node.js 16.20.0. The simple app runs just fine locally using sam local start-api, but when I try to run the debug config, I get the following error:

Debugger attached.
2023-05-03T03:22:47.313Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module 'app'","Require stack:","- /var/runtime/index.mjs","    at _loadUserApp (file:///var/runtime/index.mjs:997:17)","    at async Object.load (file:///var/runtime/index.mjs:1032:21)","    at async start (file:///var/runtime/index.mjs:1195:23)","    at async file:///var/runtime/index.mjs:1201:1"]}
Waiting for the debugger to disconnect...

My launch.json file contains the “straight out of the box” debug config and looks like this.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "API sam-app:HelloWorldFunction (nodejs16.x)",
      "invokeTarget": {
        "target": "api",
        "templatePath": "${workspaceFolder}/template.yaml",
        "logicalId": "HelloWorldFunction"
      },
      "api": {
        "path": "/hello",
        "httpMethod": "get",
        "payload": {
          "json": {}
        }
      },
      "lambda": {
        "runtime": "nodejs16.x"
      }
    }
  ]
}

What am I doing wrong? Thanks!

Expected behavior

The debugger should run without error, stopping at my first breakpoint.

System details (run the AWS: About Toolkit command)

  • OS: Darwin arm64 22.4.0 (Ventura 13.3.1 - M1 chip)
  • Visual Studio Code version: 1.77.3
  • AWS Toolkit version: 1.71.0
  • AWS SAM CLI: 1.82.0

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 23 (11 by maintainers)

Most upvoted comments

Hi @justinmk3,

I have good news to report. I was able to get debugging the API working! 🥳

Without an override.yaml file present, I set the sam.buildDir property of my debug config to .aws-sam/build. Just some folder that would be local to the project, but this seemed like a good directory. When I did this, the debugger successfully stopped at my set breakpoint!

(Note that I did upgrade to Rancher Desktop 1.9.1, but without sam.buildDir set up this way, debugging still failed.)

So, does this seem like possibly a permissions issue?

Glad I have it working once again, though! Thanks for your help!

Thanks again, @justinmk3 !

Yes. I do have “Administrative Access” turned on and I’m running the latest Rancher Desktop 1.8.1. I just re-downloaded and installed Rancher Desktop 1.8.1 again, just for kicks, but I still run into the same problem when attempting to debug.

I also went ahead and installed Docker Desktop 4.19.0 and I was successfully able to run the debugger in VS Code, so it’s looking like things aren’t playing well with Rancher Desktop.

Thank you!

Thanks again.

I’ll have to look into the latter 2 suggestions you provided. I’m not familiar with them.

As for testing out Docker Desktop temporarily, I can sure try that.

For all of these, though, it will probably be a while (at least a few weeks) before I can try them out, though, as I’m about to go on vacation for 2.5 weeks and have some things I need to finish up first. 🙂 I will be sure to follow-up, though.

Thanks!