如何设置VSCode在本地调试AWS Lambda?

时间:2019-10-17 12:13:27

标签: amazon-web-services debugging visual-studio-code aws-lambda serverless-application-model

我开始使用AWS Lambda。我选择的编辑器是VSCode。我观看了official introduction,了解如何为此任务设置VSCode。在此处,“讲师”使用GUI来在本地调试功能或通过单击“在本地运行”或“在本地调试”在本地运行该功能。

enter image description here

我想使用task.json和launch.json文件进行此操作。对我而言,这似乎比单击GUI更加简化。 有人知道task.json和launch.json的样子吗?

我对此是

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Remote Attach",
      "type": "python",
      "request": "attach",
      "port": 5858,
      "host": "127.0.0.1",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}/python_test_application",
          "remoteRoot": "/var/task",
          "protocol": "legacy"
        }
      ] 
    }
  ]
}

task.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "samLocalInvoke",
      "type": "shell",
      "command": "sam", 
      // this is what vscode runs on "Debug Locally", so lets also run it here
      // sam local invoke awsToolkitSamLocalResource --template /tmp/aws-toolkit-vscode/vsctkYQFIA5/output/template.yaml --event /tmp/aws-toolkit-vscode/vsctkYQFIA5/event.json --env-vars /tmp/aws-toolkit-vscode/vsctkYQFIA5/env-vars.json -d 5858"
      "args": [
        "local",
        "invoke",
        "awsToolkitSamLocalResource",
        "--template",
        "/tmp/aws-toolkit-vscode/vsctk7WXgnB/output/template.yaml",
        "--event",
        "/tmp/aws-toolkit-vscode/vsctk7WXgnB/event.json",
        "--env-vars",
        "/tmp/aws-toolkit-vscode/vsctk7WXgnB/env-vars.json",
        "-d",
        "5858"
      ] 
    }
  ]
}

这种方法有效,但效果不佳。更好的解决方案是始终先构建然后通过变量动态使用构建目录(此处为vsctk7WXgnB)。

即使我重新构建,应用程序有时也会忽略我的断点。

0 个答案:

没有答案