How to Debug AWS python lambdas using serverless offline through VS Code?
Asked Answered
B

1

12

I'm trying to figure out a way to debug AWS python lambdas in VS Code using the serverless framework and serverless offline. I have gotten to the point where I can run the lambdas in VS Code, but I can't set breakpoints. I'm not sure if this is possible, but from what I've read, it seems like it may be. If anyone can help, it would be much appreciated.

This is my current launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug",
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "run-script",
                "debug"
            ],
            "port": 9229,
        }
    ]
}

Scripts section of package.json is as follows:

"scripts": {
    "start": "./node_modules/.bin/serverless offline -s dev",
    "debug": "export SLS_DEBUG=* && node --inspect ./node_modules/.bin/serverless offline -s dev"
  }

Again, this setup works. I just would like the ability to set breakpoints in my .py files. When I hover over the breakpoints in the left gutter, they're greyed out and read Breakpoint ignored because generated code not found (source map problem?). I'm not sure how to get around this, given that python files don't have source maps. I tried setting the outfile field of launch.json to be the python files themselves, but that obviously didn't work.

Thanks in advance to those of you that are able to help.

NOTE: I know there is a way to get this to work with AWS SAM CLI, but unfortunately, that is not an option for me. Must be serverless framework.

EDIT: I thought this should be possible, however, the more I look into it, the more skeptical I become. If you can even inform for certain that this is not possible, it would be much appreciated! I've been hunting around for a while now with no further developments.

Bluegill answered 12/3, 2020 at 15:31 Comment(0)
F
1

Alot has changed since you asked the question, but i thought i would share some useful links that helped me sort this out.

  1. You will need the sam cli https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
  2. You will need aws tool kit for vs code https://aws.amazon.com/visualstudiocode/?sc_channel=EL&sc_campaign=Explainer_2019_vid&sc_medium=YouTube&sc_content=video4541&sc_detail=DEVELOPERTOOLS&sc_country=US
  3. Make sure Docker is installed locally https://docs.docker.com/get-docker/
  4. AWS docs to debug within VSCODE https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-no-template.html

Also, I found this simple instructional https://www.youtube.com/watch?v=FINV-VmCXms

Happy debugging!

Function answered 12/6, 2022 at 19:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.