如何通过 VS Code 使用无服务器离线调试 AWS python lambdas?

jad*_*n42 7 python debugging amazon-web-services serverless-framework serverless-offline

我正在尝试找出一种使用无服务器框架和无服务器离线在 VS Code 中调试 AWS python lambdas 的方法。我已经到了可以在 VS Code 中运行 lambdas 的地步,但我无法设置断点。我不确定这是否可能,但从我读过的内容来看,它似乎是可能的。如果有人可以提供帮助,将不胜感激。

这是我当前的launch.json:

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

package.json 的脚本部分如下:

"scripts": {
    "start": "./node_modules/.bin/serverless offline -s dev",
    "debug": "export SLS_DEBUG=* && node --inspect ./node_modules/.bin/serverless offline -s dev"
  }
Run Code Online (Sandbox Code Playgroud)

同样,此设置有效。我只是希望能够在我的 .py 文件中设置断点。当我将鼠标悬停在左侧装订线中的断点上时,它们会变灰并显示Breakpoint ignored because generated code not found (source map problem?).我不知道如何解决这个问题,因为 python 文件没有源映射。我尝试将outfilelaunch.json的字段设置为python 文件本身,但这显然不起作用。

在此先感谢那些能够提供帮助的人。

注意:我知道有一种方法可以让它与 AWS SAM CLI 一起使用,但不幸的是,这不是我的选择。必须是无服务器框架。

编辑:我认为这应该是可能的,但是,我研究得越多,我就越怀疑。如果您甚至可以确定这是不可能的,我们将不胜感激!我已经搜索了一段时间,没有进一步的发展。

小智 1

自从你提出这个问题以来,很多事情都发生了变化,但我想我会分享一些有用的链接来帮助我解决这个问题。

  1. 您将需要 sam cli https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html
  2. 您将需要用于 vs 代码的 aws 工具包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. 确保 Docker 已本地安装https://docs.docker.com/get-docker/
  4. 用于在 VSCODE 中调试的 AWS 文档https://docs.aws.amazon.com/toolkit-for-vscode/latest/userguide/serverless-apps-run-debug-no-template.html

另外,我发现了这个简单的指导https://www.youtube.com/watch?v=FINV-VmCXms

调试愉快!