Hey <@U01J5Q8HV5Z>, <@U01JVDKASAC>, I've successfu...
# help
Hey @Jay, @Frank, I've successfully followed the Guide and build the Tasks app. I'm using Python for my Lambda functions. How do I create a config to use the VSCode debugger for my Python Lambdas?
@Jason S I had exactly the same problem and got it working by checking out the VSCode debugging help
Here are the steps: 1) install
with pip 2) Add a launch configuration for Python in
Copy code
  "version": "0.2.0",
  "configurations": [
      "name": "Debug SST Start",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/sst",
      "runtimeArgs": [
      "console": "integratedTerminal",
      "skipFiles": [
      "env": {}
      "name": "Python: Attach",
      "type": "python",
      "localRoot": "${workspaceFolder}/backend/functions",
      "request": "attach",
      "host": "localhost",
      "port": 5678
3) modify the python startup related code in node_modules/@serverless-stack/core/dist/runtime/handler/python.js and replace
(line 76 for me) by
"-m", "debugpy", "--listen", "" , "--wait-for-client",
4) Make sure you increase the timeout for sst in package.json
Copy code
  "scripts": {
    "start": "sst start --increase-timeout", // <--
option means you now have to launch the debugger (F5 for me on Windows) for the function to run
@Jay @Frank could you perhaps later include an option to read an extra parameter when starting sst that could be passed to the python runtime handler and allow an easy choice for a user to wait for the debugger without my hack 🙂?
Klause thanks mate for this. I would have never sorted it out.
When I run as described,
returns the following:
RuntimeError: Can't listen for client connections: [Errno 48] Address already in use
I changed the port thinking I had something running on
from previous attempts with no success
Or are you pointing to a specific function in your
1. make sure that you are not debugging SST already 2. for linux environments, there is an easy way to kill app listening on a port - https://stackoverflow.com/questions/9346211/how-to-kill-a-process-on-a-port-on-ubuntu 3. for windows there is something similar https://stackoverflow.com/questions/39632667/how-do-i-kill-the-process-currently-using-a-port-on-localhost-in-windows
but in worst case, you can also specify a different port (it needs to be the same in the command line parameter and your debug configuration)
The root in launch.json also has to match the folder setup you have (I just used the one from the python starter example)
Hm nothing is running at that port. I tried switching ports to something else - no luck.
I assume I need to re-run
npx sst start
after making the changes to
, right?
I think this won't work as it's creates a new repo and reinstalls node modules
after the change to
you just run
npm run start
(whihc use the modified file in the current project
the parameters for running the function are only generated when sst starts, so a new run is needed
I also updated the instructions above with 4) (just in case you didn't increase the timeout for SST in package.json yet)
Are you putting any
imports or method calls within your lambda function?
No - that's not needed with the modified
An alternative would be to not modify the file + run debugpy directly in the handler itself, but perhaps it's less elegant this way - it depends a bit if you need to debug all functions or not
This is hos it would look inside the lambda function (but then you have to remove the python.js patch as they would conflict)
Copy code
# ...
# for debugging only
import debugpy
debugpy.listen(('', 5678))
@Frank I also updated the open Github Issue, with a link here, just in case someone prefers searching there
This is great @Klaus! Thanks for this. We’ll look into it.
I was able to get this working by adding the import statements into the lambda function handler directly.
I then have to trigger the lambda and run the VSCode debugger at the same time. I presume this is because the
listener is only listening during the function run.
I ran the debugger on the JS code on the python.js hander line by line. It seems like on my environment the
listening server is not being run during the SST start procedure.
After starting SST, I run
ps aux | grep debugpy
and there is no service running.
@Klaus I like your proposal - would be good to have debugpy included into node_modules/@serverless-stack/core/dist/runtime/handler/python.js and using a flag to switch between debug and normal mode. Can you create a PR for the change you did ?