aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Debug mode not starting in SAM Local

Open bscott opened this issue 8 years ago • 7 comments

Tried starting "-d" mode using invoke and start-api. Both will not listen in debug mode.

Status: Image is up to date for lambci/lambda:go1.x

Mounting dscemails (go1.x) at http://127.0.0.1:3000/collect [POST]

You can now browse to the above endpoints to invoke your functions.
You do not need to restart/reload SAM CLI while working on your functions,
changes will be reflected instantly/automatically. You only need to restart
SAM CLI if you update your AWS SAM template.

Even after sending data, VS Code Debugger still can't connect to any port I set.

Debugging with legacy protocol because Node.js version could not be determined (Error: connect ECONNREFUSED 127.0.0.1:5858)

bscott avatar Apr 04 '18 01:04 bscott

@bscott Is this still occurring in version 0.3.0? This should be addressed and work as expected.

Will leave open for a couple days. If no response, will close

jfuss avatar May 10 '18 00:05 jfuss

Yes, API Gateway in debug mode does not work. Here is the command: sam local start-api --debug-port 5858. Error message: Unable to open debugger port (localhost:5858): java.net.ConnectException "Connection refused(Connection refused)"

However, it works in function locally mode. Here is the command: sam local invoke -d 5858

dotekien avatar May 16 '18 15:05 dotekien

Starting SAM CLI in debug mode is not sufficient to attach a debugger. You should send a invoke request first to spin up the Docker container, which will make the port available for debugger to attach:

  1. Start SAM CLI start-api with --debug-port flag
  2. Send a HTTP request to the endpoint to invoke the Lambda function. At this point, the Docker container is started and your runtime process is waiting for debugger to attach
  3. Attach debugger thru IDE. this should work.

Feel free to re-open the issue if the above didn't work.

sanathkr avatar Jun 01 '18 00:06 sanathkr

Hi Is it possible to debug SAM Local with compiled languages, such as .NET Core?

fkmare avatar Jun 20 '18 05:06 fkmare

Hi, I am try to debug using the command "sam local invoke -e event.json -d 5858 HelloWorldFunction ". This command shows "Debugger listening on ws://0.0.0.0:5858/e5ee0254-d38b-4f7b-bb3f-b2b318b17493" Then my lunch.json config is { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [
{ "name": "Attach to SAM CLI", "type": "node", "request": "attach", "address": "localhost", "port": 5858, // From the sam init example, it would be "${workspaceRoot}/hello-world" "localRoot": "${workspaceRoot}", "remoteRoot": "/var/task", "protocol": "inspector"

    }
]

} and then i click play button in VScode UI. It showing errror as "Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858)"

VSCode - 1.38.1 Node runtime is -10.X @sanathkr Please help on this

SSathish89 avatar Sep 26 '19 05:09 SSathish89

Hi, I am try to debug using the command "sam local invoke -e event.json -d 5858 HelloWorldFunction ". This command shows "Debugger listening on ws://0.0.0.0:5858/e5ee0254-d38b-4f7b-bb3f-b2b318b17493" Then my lunch.json config is { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Attach to SAM CLI", "type": "node", "request": "attach", "address": "localhost", "port": 5858, // From the sam init example, it would be "${workspaceRoot}/hello-world" "localRoot": "${workspaceRoot}", "remoteRoot": "/var/task", "protocol": "inspector"

    }
]

} and then i click play button in VScode UI. It showing errror as "Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858)"

VSCode - 1.38.1 Node runtime is -10.X @sanathkr Please help on this

@sanathkr I'm getting the same error, did you solve this somehow?

Jkap7788 avatar Nov 20 '19 06:11 Jkap7788

Hi, I am try to debug using the command "sam local invoke -e event.json -d 5858 HelloWorldFunction ". This command shows "Debugger listening on ws://0.0.0.0:5858/e5ee0254-d38b-4f7b-bb3f-b2b318b17493" Then my lunch.json config is { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Attach to SAM CLI", "type": "node", "request": "attach", "address": "localhost", "port": 5858, // From the sam init example, it would be "${workspaceRoot}/hello-world" "localRoot": "${workspaceRoot}", "remoteRoot": "/var/task", "protocol": "inspector"

    }
]

} and then i click play button in VScode UI. It showing errror as "Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858)" VSCode - 1.38.1 Node runtime is -10.X @sanathkr Please help on this

@sanathkr I'm getting the same error, did you solve this somehow?

I could solve it by setting the following setting for the localArguments in the sam field: "localArguments": [ "--container-host-interface=host.docker.internal" ] Seems that binding to 127.0.0.1 does not work since the container should bind the port to the host interface and not only within the container

ireznik avatar Apr 21 '23 05:04 ireznik