Skip to content
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

(Colima) sam local invoke Command Succeeds, but VSCode Debugging Fails #5024

Open
skurihara-cw opened this issue May 20, 2024 · 4 comments
Open
Labels
lambda-arm needs-response Waiting on reply from issue/PR author. sam

Comments

@skurihara-cw
Copy link

Environment Information

  • macOS 14.5 (BuildVersion: 23F79)
  • ARM64 Architecture
  • SAM CLI Version: 1.116.0
  • vscode 1.89.1 (Universal)
  • Toolkit v3.5.0

Summary of Issue

The sam local invoke command runs successfully from the terminal, but attempting to run the Lambda function using VSCode's debug feature fails.

Steps to Reproduce

  1. Start Colima and Docker.
  2. Create a new project using sam init.
  3. Set the DOCKER_HOST environment variable.
  4. Confirm successful execution by running sam local invoke from the terminal.
  5. Configure the following launch.json in VSCode:
{
  "configurations": [
    {
      "type": "aws-sam",
      "request": "direct-invoke",
      "name": "sam-app:HelloWorldFunction",
      "invokeTarget": {
        "target": "template",
        "templatePath": "${workspaceFolder}/template.yaml",
        "logicalId": "HelloWorldFunction"
      },
      "lambda": {
        "payload": {},
        "environmentVariables": {}
      }
    }
  ]
}
  1. Run sam-app:HelloWorldFunction using VSCode's debug feature.

Expected Results

VSCode's debug execution should succeed, running the Lambda function just as it does from the terminal.

Actual Results

VSCode's debug execution fails with the following error:

2024-05-20 18:28:35.438 [info] AWS.running.command
2024-05-20 18:28:36.525 [info] Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?
2024-05-20 18:28:36.595 [info]
2024-05-20 18:28:36.595 [info] Command stopped: "sam local invoke"

Troubleshooting Steps Taken

  • Set Colima's Docker socket to the DOCKER_HOST environment variable.

Logs and Commands

AWS Toolkit log from VSCode:

2024-05-20 18:28:26.662 [info] Preparing to debug locally: Lambda "app.lambda_handler"
2024-05-20 18:28:26.662 [info] Building SAM application...
2024-05-20 18:28:26.920 [info] Command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctk713923bc/output --template /Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/template.yaml --manifest /tmp/aws-toolkit-vscode/vsctk713923bc/debug-requirements.txt]
2024-05-20 18:28:27.517 [info] Starting Build use cache
2024-05-20 18:28:27.554 [info] Manifest file is changed (new hash: c52a23f758edd66a90b9a184e05a0d39) or dependency folder (.aws-sam/deps/26d41fd4-e674-40ea-a0f2-83f01ef00b13) is missing for (HelloWorldFunction), downloading dependencies and copying/building source
Building codeuri: /Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/hello_world runtime: python3.9 metadata: {} architecture: x86_64 functions: HelloWorldFunction
2024-05-20 18:28:28.579 [info] Running PythonPipBuilder:CleanUp
2024-05-20 18:28:28.579 [info] Running PythonPipBuilder:ResolveDependencies
2024-05-20 18:28:34.280 [info] Running PythonPipBuilder:CopySource
2024-05-20 18:28:34.549 [info] Running PythonPipBuilder:CopySource
2024-05-20 18:28:34.557 [info] Build Succeeded
2024-05-20 18:28:34.557 [info] Built Artifacts  : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk713923bc/output
Built Template   : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk713923bc/output/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke -t ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk713923bc/output/template.yaml
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided --template-file ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk713923bc/output/template.yaml
2024-05-20 18:28:35.189 [info] Build complete.
2024-05-20 18:28:35.189 [info] Starting SAM application locally
2024-05-20 18:28:35.438 [info] AWS.running.command
2024-05-20 18:28:36.525 [info] Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running?
2024-05-20 18:28:36.595 [info]
2024-05-20 18:28:36.595 [info] Command stopped: "sam local invoke"

Manually executed commands:

sw_vers
uname -m
sam --version
colima start
docker context ls
sam init
cd sam-app/
code . -n

sam local invoke
export DOCKER_HOST=unix:///Users/XXX/.colima/default/docker.sock
docker context ls
sam local invoke

Request

Please provide a solution to enable successful debug execution in VSCode. Are there any additional settings or steps required?

Thank you.

@skurihara-cw skurihara-cw added the bug We can reproduce the issue and confirmed it is a bug. label May 20, 2024
@skurihara-cw
Copy link
Author

Using Docker Desktop instead of Colima works without issues. I suspect the problem is related to the Docker default socket configuration.

@justinmk3 justinmk3 added the sam label May 20, 2024
@justinmk3
Copy link
Contributor

Using Docker Desktop instead of Colima works without issues. I suspect the problem is related to the Docker default socket configuration.

Thanks, yes, that's likely a SAM CLI question. See also #3413 (comment)

@justinmk3 justinmk3 added needs-response Waiting on reply from issue/PR author. lambda-arm and removed bug We can reproduce the issue and confirmed it is a bug. labels May 20, 2024
@skurihara-cw
Copy link
Author

skurihara-cw commented May 21, 2024

For some reason, there is a pattern where the above error is not output and processing proceeds. In that case, a different error is output.
I think this error is about SAM's debug.

debugpy error

2024-05-21 09:51:23.254 [info] Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

Mounting /tmp/aws-toolkit-vscode/vsctk5042e571/output/HelloWorldFunction as /var/task:ro,delegated, inside runtime container
2024-05-21 09:51:24.603 [info] START RequestId: be6a81f1-95db-4920-a7a2-32eacf6f15b6 Version: $LATEST
2024-05-21 09:51:24.866 [info] Prepending Lambda task root to path: /var/task
Starting debugger...
2024-05-21 09:51:24.875 [info] 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 "/var/lang/lib/python3.9/runpy.py", line 221, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/var/lang/lib/python3.9/runpy.py", line 141, in _get_module_details
    raise error("No module named { raw: true }" % mod_name)
ImportError: No module named debugpy
2024-05-21 09:51:24.900 [info] 21 May 2024 00:51:24,910 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID=
2024-05-21 09:51:24.903 [info] 21 May 2024 00:51:24,916 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 1 InvokeID=a9dac734-d8be-4e56-88f2-a11d52064cd4
2024-05-21 09:51:24.907 [info] 21 May 2024 00:51:24,920 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
2024-05-21 09:51:25.917 [info]
2024-05-21 09:51:27.190 [info] Attaching debugger to SAM application...
2024-05-21 09:52:06.350 [error] SamLaunchRequestError: Failed to attach debugger [DebuggerRetryLimit]

Error pop-ups were also displayed.

connect ECONNREFUSED 127.0.0.1:5858

Full log of the Toolkit

2024-05-21 09:50:39.804 [info] Log level: info
2024-05-21 09:50:39.805 [info] endpoints: retrieving AWS endpoints data
2024-05-21 09:50:39.805 [info] Telemetry product: AWS Toolkit For VS Code
2024-05-21 09:50:39.954 [info] OS: Darwin arm64 23.5.0
2024-05-21 09:50:39.954 [info] Visual Studio Code extension host:  1.89.1
2024-05-21 09:50:39.954 [info] AWS Toolkit:  3.5.0
2024-05-21 09:50:39.954 [info] node: 18.18.2
2024-05-21 09:50:39.954 [info] electron: 28.2.8
2024-05-21 09:50:39.976 [info] initialized 'submitFeedback' command with default feedback id: AWS Toolkit
2024-05-21 09:50:40.041 [info] current client registration id=undefined, 
    expires at undefined, 
    key = undefined
2024-05-21 09:50:40.041 [info] auth: Updating connection state of profile:kurihara-dev-admin to invalid
2024-05-21 09:50:40.595 [error] Ec2MetadataClient failed to fetch token: TimeoutError: Connection timed out after 500ms ()
2024-05-21 09:50:56.471 [info] CloudFormationTemplateRegistry: building with: Watching **/*.{yaml,yml,json,template}, Untitled Files, Excluding /.*devfile\.(yaml|yml)/i, /.*[/\\]\.aws-sam([/\\].*|$)/
2024-05-21 09:50:56.502 [info] CloudFormationTemplateRegistry: failed to process: file:///Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/events/event.json
2024-05-21 09:50:56.504 [info] CloudFormationTemplateRegistry: failed to process: file:///Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/.vscode/launch.json
2024-05-21 09:50:56.507 [info] CloudFormationTemplateRegistry: processed 1 items, skipped 2
2024-05-21 09:50:56.512 [warning] SAM debug: missing AWS credentials (Toolkit is not connected)
2024-05-21 09:50:57.296 [info] SAM CLI location (version: 1.116.0): /usr/local/bin/sam
2024-05-21 09:50:58.126 [info] Preparing to debug locally: Lambda "app.lambda_handler"
2024-05-21 09:50:58.126 [info] Building SAM application...
2024-05-21 09:50:58.381 [info] SAM CLI not configured, using SAM found at: '/usr/local/bin/sam'
2024-05-21 09:50:58.381 [info] Command: (not started) [/usr/local/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctk5042e571/output --template /Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/template.yaml --manifest /tmp/aws-toolkit-vscode/vsctk5042e571/debug-requirements.txt]
2024-05-21 09:50:58.975 [info] Starting Build use cache
2024-05-21 09:50:59.012 [info] Manifest file is changed (new hash: c52a23f758edd66a90b9a184e05a0d39) or dependency folder (.aws-sam/deps/a4efe1ae-7f0f-4144-8550-33208d56c662) is missing for (HelloWorldFunction), downloading dependencies and copying/building source
Building codeuri: /Users/XXX/Develop/coding/sandbox/2024-05-20-sam-debug/sam-app/hello_world runtime: python3.9 metadata: {} architecture: x86_64 functions: HelloWorldFunction
2024-05-21 09:50:59.808 [info] Running PythonPipBuilder:CleanUp
2024-05-21 09:50:59.808 [info] Running PythonPipBuilder:ResolveDependencies
2024-05-21 09:51:02.367 [info] Running PythonPipBuilder:CopySource
2024-05-21 09:51:02.750 [info] Running PythonPipBuilder:CopySource
2024-05-21 09:51:02.789 [info] Build Succeeded
2024-05-21 09:51:02.789 [info] Built Artifacts  : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk5042e571/output
Built Template   : ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk5042e571/output/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke -t ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk5042e571/output/template.yaml
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided --template-file ../../../../../../../private/tmp/aws-toolkit-vscode/vsctk5042e571/output/template.yaml
2024-05-21 09:51:03.403 [info] Build complete.
2024-05-21 09:51:03.403 [info] Starting SAM application locally
2024-05-21 09:51:03.641 [info] SAM CLI not configured, using SAM found at: '/usr/local/bin/sam'
2024-05-21 09:51:03.641 [info] AWS.running.command
2024-05-21 09:51:03.641 [info] Command: (not started) [/usr/local/bin/sam local invoke HelloWorldFunction --template /tmp/aws-toolkit-vscode/vsctk5042e571/output/template.yaml -d 5858 --debugger-path /Users/XXX/.vscode/extensions/amazonwebservices.aws-toolkit-vscode-3.5.0/resources/debugger --debug-args /tmp/lambci_debug_files/py_debug_wrapper.py --listen 0.0.0.0:5858 --wait-for-client --log-to-stderr]
2024-05-21 09:51:04.277 [info] Invoking app.lambda_handler (python3.9)
2024-05-21 09:51:09.143 [info] Local image is out of date and will be updated to the latest runtime. To skip this, pass in the parameter --skip-pull-image
Building image...
2024-05-21 09:51:09.417 [info] ..
2024-05-21 09:51:11.360 [info] ..
2024-05-21 09:51:11.370 [info] .
2024-05-21 09:51:11.371 [info] ......
2024-05-21 09:51:11.887 [info] .
2024-05-21 09:51:11.888 [info] .
2024-05-21 09:51:11.892 [info] .
2024-05-21 09:51:11.894 [info] .
2024-05-21 09:51:11.910 [info] .
2024-05-21 09:51:11.911 [info] ...
2024-05-21 09:51:11.912 [info] .
2024-05-21 09:51:11.915 [info] .
2024-05-21 09:51:11.938 [info] .
2024-05-21 09:51:11.942 [info] .
2024-05-21 09:51:11.943 [info] .
2024-05-21 09:51:11.958 [info] .
2024-05-21 09:51:11.992 [info] .
2024-05-21 09:51:12.094 [info] .
2024-05-21 09:51:12.129 [info] ..
2024-05-21 09:51:12.130 [info] .
2024-05-21 09:51:12.177 [info] .
2024-05-21 09:51:12.186 [info] .
2024-05-21 09:51:12.467 [info] .
2024-05-21 09:51:12.503 [info] .
2024-05-21 09:51:12.586 [info] .
2024-05-21 09:51:12.654 [info] .
2024-05-21 09:51:12.725 [info] .
2024-05-21 09:51:12.812 [info] .
2024-05-21 09:51:12.899 [info] .
2024-05-21 09:51:12.923 [info] .
2024-05-21 09:51:13.014 [info] .
2024-05-21 09:51:13.031 [info] .
2024-05-21 09:51:13.136 [info] .
2024-05-21 09:51:13.171 [info] .
2024-05-21 09:51:13.238 [info] .
2024-05-21 09:51:13.327 [info] .
2024-05-21 09:51:13.343 [info] .
2024-05-21 09:51:13.445 [info] .
2024-05-21 09:51:13.480 [info] .
2024-05-21 09:51:13.551 [info] .
2024-05-21 09:51:13.635 [info] .
2024-05-21 09:51:13.656 [info] .
2024-05-21 09:51:13.792 [info] .
2024-05-21 09:51:13.794 [info] .
2024-05-21 09:51:13.922 [info] .
2024-05-21 09:51:13.958 [info] .
2024-05-21 09:51:14.066 [info] .
2024-05-21 09:51:14.081 [info] .
2024-05-21 09:51:14.178 [info] .
2024-05-21 09:51:14.243 [info] .
2024-05-21 09:51:14.281 [info] .
2024-05-21 09:51:14.353 [info] .
2024-05-21 09:51:14.407 [info] .
2024-05-21 09:51:14.486 [info] .
2024-05-21 09:51:14.525 [info] .
2024-05-21 09:51:14.646 [info] .
2024-05-21 09:51:14.660 [info] .
2024-05-21 09:51:14.760 [info] .
2024-05-21 09:51:14.831 [info] .
2024-05-21 09:51:14.878 [info] .
2024-05-21 09:51:14.982 [info] .
2024-05-21 09:51:15.011 [info] .
2024-05-21 09:51:15.109 [info] .
2024-05-21 09:51:15.152 [info] .
2024-05-21 09:51:15.226 [info] .
2024-05-21 09:51:15.322 [info] .
2024-05-21 09:51:15.336 [info] .
2024-05-21 09:51:15.447 [info] .
2024-05-21 09:51:15.475 [info] .
2024-05-21 09:51:15.578 [info] .
2024-05-21 09:51:15.603 [info] .
2024-05-21 09:51:15.603 [info] ..
2024-05-21 09:51:15.629 [info] .
2024-05-21 09:51:15.738 [info] .
2024-05-21 09:51:15.882 [info] .
2024-05-21 09:51:16.025 [info] .
2024-05-21 09:51:16.168 [info] .
2024-05-21 09:51:16.310 [info] .
2024-05-21 09:51:16.451 [info] .
2024-05-21 09:51:16.591 [info] .
2024-05-21 09:51:16.731 [info] .
2024-05-21 09:51:16.875 [info] .
2024-05-21 09:51:17.018 [info] .
2024-05-21 09:51:17.161 [info] .
2024-05-21 09:51:17.301 [info] .
2024-05-21 09:51:17.447 [info] .
2024-05-21 09:51:17.590 [info] .
2024-05-21 09:51:17.728 [info] .
2024-05-21 09:51:17.871 [info] .
2024-05-21 09:51:18.015 [info] .
2024-05-21 09:51:18.157 [info] .
2024-05-21 09:51:18.305 [info] .
2024-05-21 09:51:18.448 [info] .
2024-05-21 09:51:18.593 [info] .
2024-05-21 09:51:18.734 [info] .
2024-05-21 09:51:18.881 [info] .
2024-05-21 09:51:18.982 [info] .
2024-05-21 09:51:19.021 [info] .
2024-05-21 09:51:19.022 [info] .
2024-05-21 09:51:19.097 [info] .
2024-05-21 09:51:19.202 [info] .
2024-05-21 09:51:19.315 [info] .
2024-05-21 09:51:19.418 [info] .
2024-05-21 09:51:19.522 [info] .
2024-05-21 09:51:19.650 [info] .
2024-05-21 09:51:19.852 [info] .
2024-05-21 09:51:19.964 [info] .
2024-05-21 09:51:20.090 [info] .
2024-05-21 09:51:20.202 [info] .
2024-05-21 09:51:20.310 [info] .
2024-05-21 09:51:20.411 [info] .
2024-05-21 09:51:20.546 [info] .
2024-05-21 09:51:20.676 [info] .
2024-05-21 09:51:20.783 [info] .
2024-05-21 09:51:20.900 [info] .
2024-05-21 09:51:21.025 [info] .
2024-05-21 09:51:21.172 [info] .
2024-05-21 09:51:21.280 [info] .
2024-05-21 09:51:21.429 [info] .
2024-05-21 09:51:21.569 [info] .
2024-05-21 09:51:21.671 [info] .
2024-05-21 09:51:21.771 [info] .
2024-05-21 09:51:21.875 [info] .
2024-05-21 09:51:21.897 [info] .
2024-05-21 09:51:22.028 [info] .
2024-05-21 09:51:22.037 [info] .
2024-05-21 09:51:22.139 [info] .
2024-05-21 09:51:22.242 [info] .
2024-05-21 09:51:22.346 [info] .
2024-05-21 09:51:22.446 [info] .
2024-05-21 09:51:22.554 [info] .
2024-05-21 09:51:22.621 [info] .
2024-05-21 09:51:22.676 [info] .
2024-05-21 09:51:22.682 [info] .
2024-05-21 09:51:22.684 [info] .
2024-05-21 09:51:22.684 [info] ...
2024-05-21 09:51:22.858 [info] .
2024-05-21 09:51:22.858 [info] ..
2024-05-21 09:51:22.890 [info] ..
2024-05-21 09:51:23.238 [info] .
2024-05-21 09:51:23.240 [info] ...
2024-05-21 09:51:23.244 [info] .
2024-05-21 09:51:23.254 [info] Using local image: public.ecr.aws/lambda/python:3.9-rapid-x86_64.

Mounting /tmp/aws-toolkit-vscode/vsctk5042e571/output/HelloWorldFunction as /var/task:ro,delegated, inside runtime container
2024-05-21 09:51:24.603 [info] START RequestId: be6a81f1-95db-4920-a7a2-32eacf6f15b6 Version: $LATEST
2024-05-21 09:51:24.866 [info] Prepending Lambda task root to path: /var/task
Starting debugger...
2024-05-21 09:51:24.875 [info] 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 "/var/lang/lib/python3.9/runpy.py", line 221, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/var/lang/lib/python3.9/runpy.py", line 141, in _get_module_details
    raise error("No module named { raw: true }" % mod_name)
ImportError: No module named debugpy
2024-05-21 09:51:24.900 [info] 21 May 2024 00:51:24,910 [ERROR] (rapid) Init failed error=Runtime exited with error: exit status 1 InvokeID=
2024-05-21 09:51:24.903 [info] 21 May 2024 00:51:24,916 [ERROR] (rapid) Invoke failed error=Runtime exited with error: exit status 1 InvokeID=a9dac734-d8be-4e56-88f2-a11d52064cd4
2024-05-21 09:51:24.907 [info] 21 May 2024 00:51:24,920 [ERROR] (rapid) Invoke DONE failed: Sandbox.Failure
2024-05-21 09:51:25.917 [info] 
2024-05-21 09:51:27.190 [info] Attaching debugger to SAM application...
2024-05-21 09:52:06.350 [error] SamLaunchRequestError: Failed to attach debugger [DebuggerRetryLimit]
2024-05-21 09:55:40.813 [info] telemetry: sent batch (size=10)
image

@justinmk3
Copy link
Contributor

ImportError: No module named debugpy

debugpy must be in the lambda that is deployed to the docker container. AWS Toolkit tries to do this for you, but if it's not working you may need to add debugpy to you requirements.txt

@justinmk3 justinmk3 changed the title sam local invoke Command Succeeds, but VSCode Debugging Fails (Colima) sam local invoke Command Succeeds, but VSCode Debugging Fails May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lambda-arm needs-response Waiting on reply from issue/PR author. sam
Projects
None yet
Development

No branches or pull requests

2 participants