-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SAM debugging fails (using colima) #6156
Comments
Hello @zachlipton Thank you for raise this issue. I wasn't able to reproduce the issue you are experiencing for version 3.36, 3.37 Test for X86
Test for arm64
I used sam init via the terminal to generate an Hello world function of runtime nodejs20 with zip package type and then clicked on invoke via the app-builder. Is this consistent with the steps you took to get this error? If yes Upon closer examination of the error log, it's evident that we're dealing with a module import issue within the Lambda runtime environment. The specific error message, "Error: Cannot find module 'app'", is particularly telling and warrants further investigation. Could this be that a) The file 'app.js' or 'app.mjs' doesn't exist in the project. If No: Do you mind pointing out are divergence in the our steps |
Thanks @jonife! app.mjs exists in the project. It's created by the template, and for the sake of this testcase, I didn't modify the code or anything from the template in any way; I just used it the way "AWS: Create Lambda SAM Application" created it. When I do that, If it's helpful, here's a zip of the entire project as it was created by "AWS: Create Lambda SAM Application" (this one is nodejs22.x but the behavior is the same with nodejs20.x as well). It sounds like you created the Hello World function with The main distinction I can see is that when I run
But when I invoke the function within the vscode UI, it does two things differently. It attaches the debugger, and it mounts the task's code from a directory in
I have no idea if that's at all relevant to why it works in the terminal but not when running from inside vscode. |
Ok I figured out what's going on. I copied the project into Which made me realize the issue isn't exactly with invoking the function from vscode; it's that it works when the code is in my homedir but invoking the function fails when aws-toolkit-vscode copies it to The workaround that fixex it for me was to run So I suppose this isn't exactly an aws-toolkit-vscode bug. Fundamentally, it's a docker/colima configuration issue, but an extremely non-obvious one with little in the way of debug messages or online resources to aid diagnosis. It turns out this situation is documented by colima, but because it fails silently, you'd have to already know what's wrong to have any hope of finding that documentation. I suppose it would be ideal if the toolkit put the output somewhere under the project directory rather than /tmp/aws-toolkit-vscode to avoid this. Or at least detected this condition and provided a suggestion on how to fix it. Up to you if you want to close the issue as out of scope or if there's a way the toolkit or aws-sam-cli could help people out who run into this error, since it's triggered by the fact the toolkit copies everything to /tmp/aws-toolkit-vscode. Either way, at least I hope this info helps others. |
Agreed! Tracked in #2050 Thanks for that very helpful debugging info. |
Problem
When using the built-in Hello World nodejs Lambda template, invoking the default launch configuration results in a JavaScript
ImportModule Error: Error: Cannot find module 'app'
while manually runningsam local invoke
in the terminal works fine.Steps to reproduce the issue
Actual behavior
2024-12-05 01:04:36.659 [info] 2024-12-05T09:04:36.727Z 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:1087:17)"," at async Object.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}
The full log output by Run and Debug is attached: vscode.txt
Expected behavior
The function is invoked locally.
The odd thing is that if I switch to the terminal tab and run
cd lambda-nodejs20.x && sam local invoke
, it works as expected and outputs the hello world response sucuessfully. It works just running the sam-cli directly in the terminal, but always fails to find the module when invoked through the vscode launch configuration. I get the same behavior in my actual project, but simplified it down to the built-in hello world template for the purpose of this report.System details (run
AWS: About
and/orAmazon Q: About
)The text was updated successfully, but these errors were encountered: