aws-toolkit-vscode icon indicating copy to clipboard operation
aws-toolkit-vscode copied to clipboard

debugging with `"type": "aws-sam"` launch configuration fails

Open royassis opened this issue 7 months ago • 1 comments

Problem

When trying to run a local lambda function with configuration of type aws-sam. Getting

connect ECONNREFUSED 127.0.0.1:5858

When using the sam cmd vscode is invoking and running it manually in powershell i'm getting:

(general-env) PS C:\xxxxxx\PycharmProjects\unigen_pipeline> sam.cmd `
>>     local invoke SendPipelineResultToCaller `
>>     --template C:\xxxxxx\PycharmProjects\unigen_pipeline\.aws-sam\build\template.yaml `
>>     --event C:\xxxxxx\PycharmProjects\unigen_pipeline\misc\events\SendPipelineResultToCaller.json `
>>     --env-vars C:\xxxxxx\PycharmProjects\unigen_pipeline\misc\env_vars\send_pipeline_result_to_caller.json `
>>     -d 5858 `
>>     --debugger-path c:\xxxxxx\.vscode\extensions\amazonwebservices.aws-toolkit-vscode-3.61.0\resources\debugger `
>>     --debug-args "/var/lang/bin/python3.12 /tmp/lambci_debug_files/py_debug_wrapper.py --listen 0.0.0.0:5858 --wait-for-client --log-to-stderr /var/runtime/bootstrap.py"
Invoking Container created from sendpipelineresulttocaller:latest
Building image.................
Using local image: sendpipelineresulttocaller:rapid-x86_64.

START RequestId: cfa9e12a-0cb6-4307-9708-045747d1a270 Version: $LATEST
/tmp/lambci_debug_files/py_debug_wrapper.py:22: SyntaxWarning: invalid escape sequence '\+'
  if not re.search('(I|D)\+[0-9]+\.[0-9]+:', message) or self.debug:
Prepending Lambda task root to path: /var/task
Starting debugger...
Traceback (most recent call last):
  File "/tmp/lambci_debug_files/py_debug_wrapper.py", line 46, in <module>
    runpy.run_module('debugpy', run_name='__main__')
  File "<frozen runpy>", line 222, in run_module
  File "<frozen runpy>", line 142, in _get_module_details
ImportError: No module named debugpy
18 May 2025 12:02:24,859 [ERROR] (rapid) Init failed InvokeID= error=Runtime exited with error: exit status 1
18 May 2025 12:02:24,863 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 1 InvokeID=f590ef91-402f-4ec2-9db4-d4be31693374
18 May 2025 12:02:24,864 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
  • OS: windows 11
  • Visual Studio Code version: 1.100.2
  • AWS Toolkit version: 3.62.0
  • Amazon Q version:

royassis avatar May 18 '25 12:05 royassis

The way that the AWS Toolkit debugging works is that during the build process that happens in the beginning of the debug, the debugpy package is added to the Lambda function's code dependencies, so the code can be debugged without having to make any changes to it.

Can you check if there's any visible issue during that build process? On the Output tab for the AWS Toolkit there should be some text like this:

2025-05-23 18:28:01.153 [info] Starting Build use cache
2025-05-23 18:28:01.219 [info] Manifest file is changed (new hash: c52a23f758edd66a90b9a184e05a0d39) or dependency folder (.aws-sam/deps/add75c1a-c1be-421e-9148-6fe1dfc96604) is missing for (HelloWorldFunction), downloading dependencies and copying/building source
2025-05-23 18:28:01.219 [info] Building codeuri: /home/test-user/test/python-3.13/hello_world runtime: python3.9 architecture: x86_64 functions: HelloWorldFunction
2025-05-23 18:28:01.313 [info] Running PythonPipBuilder:CleanUp
2025-05-23 18:28:01.314 [info] Running PythonPipBuilder:ResolveDependencies
2025-05-23 18:28:03.263 [info] Running PythonPipBuilder:CopySource
2025-05-23 18:28:03.335 [info] Running PythonPipBuilder:CopySource
2025-05-23 18:28:03.359 [info] Build Succeeded
2025-05-23 18:28:03.359 [info] Built Artifacts  : ../../../../../tmp/aws-toolkit-vscode/vsctk5f518d03/output
Built Template   : ../../../../../tmp/aws-toolkit-vscode/vsctk5f518d03/output/template.yaml

(of course the hashes, ids and runtime will be different)

If you don't see any issues with the build process, a temporary workaround would be to just add debugpy to your requirements.txt file. But it's interesting that for some reason that might not be added correctly to your package. Have you tried other functions to see if it fails consistently? It would be interesting to know if there's an issue with your particular function, or with your environment, or something else.

valerena avatar May 23 '25 18:05 valerena