aws / aws/aws-toolkit-vscode

(Rancher) SAM debug fails

Open
#3,413 23 comments 0 reactions 0 assignees View on GitHub
guidance sam
Dominant language
TypeScript
Stars
2k
Forks
807
Avg merge
10h 12m
Merged PRs (30d)
7

Description

## 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:

```console
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.

```json
{
"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

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with the SAM Hello World application, template.yaml, and the launch.json configuration shown in the report; first compare the working `sam local start-api` path with the AWS SAM API Gateway lambda invoke debug path. Done means the debug configuration starts without the `Cannot find module 'app'` error and stops at the first breakpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, node.js, vscode
Domain
cloud, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.