aws-sam-cli: Get an error when trying the AWS tutorial for running a Lambda locally under SAM with vscode codelens

Description

Using the vscode codelens “Debug locally” optiion to debug the simple hello-world node example gives an error.

Steps to reproduce

Follow the steps described in this short video tutorial exactly, but choose the nodejs12.x runtime. When you finally click the “Debug locally” CodeLense option above the exports.lambdaHandler = async (event, context) => { the error will be produced in the “Debug console”.

The steps listed are:

  1. open a bash terminal in WSL
  2. cd to a directory you’d keep your projects in (for me /c/var/www/lambda)
  3. In vscode CTRL-SHIFT-P
  4. Select “AWS: Create new SAM application”
  5. Select node12.x as SAM Application Runtime
  6. Select ASW SAM Hello World as SAM Application Template
  7. Enter . as the workspace folder for the new project
  8. Click okay at the path confirmation /c/var/www/lambda/
  9. enter sam-app as the name of your new app
  10. In vscode, edit the sam-app/hello-world/app.js file
  11. Insert a new line after line 19 and add console.log("We got here!");
  12. Place a breakpoint on this new line
  13. Click Configure in the CodeLens options above the exports.lambdaHandler = async (event, context) => {
  14. Click on the TERMINAL link when placed into the editor fore template.json
  15. enter sam local generate-event apigateway aws-proxy | clip 6 select the {} in the "event": {}, in templates.json and paste in the clipboard
  16. ALT-SHIFT-F to auto format
  17. Now click the ``Debug Locally"" CodeLens option in the app.js file

Observed result

The debugger first stops at the line const RAPIDClient = require(“./RAPIDClient.js”); in file index.js image After clicking the continue button in image it gets here image the clicking continue again gives the error below in the DEBUG CONSOLE

2020-05-10T16:33:02.723Z	undefined	ERROR	Uncaught Exception 	{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","stack":["Runtime.ImportModuleError: Error: Cannot find module 'app'","Require stack:","- /var/runtime/UserFunction.js","- /var/runtime/index.js","    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","    at Object.load (/var/runtime/UserFunction.js:140:17)","    at Object.<anonymous> (/var/runtime/index.js:43:30)","    at Module._compile (internal/modules/cjs/loader.js:1153:14)","    at Object..js (internal/modules/cjs/loader.js:1176:10)","    at Module.load (internal/modules/cjs/loader.js:1000:32)","    at Function._load (internal/modules/cjs/loader.js:899:14)","    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12)","    at internal/main/run_main_module.js:18:47"]}
START RequestId: b9a1ab35-1c23-10e5-fcfb-b89d7e57ac38 Version: $LATEST
END RequestId: b9a1ab35-1c23-10e5-fcfb-b89d7e57ac38
REPORT RequestId: b9a1ab35-1c23-10e5-fcfb-b89d7e57ac38	Init Duration: 20909.03 ms	Duration: 1.53 ms	Billed Duration: 100 ms	Memory Size: 128 MB	Max Memory Used: 42 MB	

{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'app'\nRequire stack:\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js"}

Expected result

I expected the working result they show in the video, which was that the debugger stops at the breakpoint on the console.log("AM is the coolest"); statement.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 10 Pro 1909 (Build 18363.815)
  2. sam --version: SAM CLI, version 0.48.0
  3. WSL bash: $ docker --version Docker version 19.03.8, build afacb8b7f0 (as client)
  4. Windows DockerDesktop version 2.2.0.5 (43884) Stable
  5. vscode: Version: 1.45.0 (system setup) Commit: d69a79b73808559a91206d73d7717ff5f798f23c Date: 2020-05-07T16:18:48.860Z Electron: 7.2.4 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 10.0.18363

Add --debug flag to command you are running

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Most upvoted comments

any idea why it always breaks in /var/runtime/index.js line 10?? const RAPIDClient = require("./RAPIDClient.js");

any idea why it always breaks in /var/runtime/index.js line 10?? const RAPIDClient = require("./RAPIDClient.js");

@ikamal-pxl @vgjenks Not sure why, but this seems to fix the issue:

Run the debugger. After it breaks, in the “CALL STACK” section, right click the second entry from the top and click “Exclude Caller”.

sam-debug

any idea why it always breaks in /var/runtime/index.js line 10?? const RAPIDClient = require("./RAPIDClient.js");

I would LOVE to know why this is. I see no resolution to this, no matter what I search for. Super annoying!