Unable to debug lambda function in vs code
Hi,
I have no experience with docker so would definitely appreciate some guidance.
I have a function called HelloWorldFunction and would like to debug it locally using sam local.
I can invoke the function with no issue using a command as follows:
$ sam local invoke -e events/event.json HelloWorldFunction
This command will successfully run the function and return a response.
I can also start a debugger by running:
sam local invoke -d 5858 -e events/event.json HelloWorldFunction
The above command will result in a response like the following:
Debugger listening on ws://0.0.0.0:5858/d30d92fc-63c1-4426-9924-c62c9f1e7be1
However, all examples and tutorials I have seen end up with a message like the following:
Debugger listening on [::]:5858
This is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "HelloWorldFunction",
"type": "node",
"request": "attach",
"address": "localhost",
"port": 5858,
"localRoot": "${workspaceRoot}/.aws-sam/build/HelloWorldFunction",
"remoteRoot": "/var/task",
"protocol": "inspector",
"stopOnEntry": false,
"outFiles": [
"${workspaceRoot}/.aws-sam/build/HelloWorldFunction/app.js"
],
"sourceMaps": true
}
}
(I'm using sam-webpack-plugin to transpile from typescript into javascript)
I am unable to debug my lambda function using vs code, I get the error message:

I have a feeling it has something to do with the address the debugger is listening on but I could be wrong!
Any help would be greatly appreciated thanks!
Extra info
- OS: windows 10 home
- Using docker toolbox, not docker desktop
- Sam cli v0.31.1
- nodejs 10.x
Still unable to solve this issue, any suggestions?
@Jkap7788 This could be due to you using docker toolbox and needing to forward requests to the VM or correct permissions. You are already using Windows 10, so you should be moving to docker for windows as docker toolbox is depreciated by docker.
I would also encourage you to use the AWS Toolkit for VSCode, which will allow for a better debug experience.
@jfuss Thanks for the reply, unfortunately Docker for windows is not available for windows 10 home, only for Pro, Enterprise or Education versions so I'm stuck with docker toolbox for now.
Additionally, the AWS toolkit does add some nice features but still doesn't allow me to debug given the current problem. It also seems to behave differently when working in typescript files rather than javascript.
Any suggestions on where to look to configure permissions or request forwarding?
Thanks!
@Jkap7788 Going off the top of my head, you will need to do port forwarding on the debug port. I would consult Docker docs on how to do this.
@jfuss Thanks for the help, finally solved it!
For anyone else in a similar position:
- Open up virtual box
- Go to settings -> Network > Advanced -> Port Forwarding
- Enter new rule: Name="sam", Protocol="TCP", Host IP="127.0.0.1", Host Port="5858", Guest IP="", Guest Port="5858"
- Run
sam local invoke <function-name>once before debugging (only had to do this once) - Run
sam local invoke -d 5858 <function-name>to start debugging