4

I am getting started with AWS Lambda. The editor of my choice is VSCode. I watched the official introduction on how to setup VSCode for this task as a start. In there, the "instructors" use the GUI to debug a function locally or to run it locally by clicking on "Run Locally" or "Debug Locally".

enter image description here

I would like to do this using the task.json and the launch.json file. This just seems more streamlined to me than clicking on a GUI. Does anybody know how task.json and launch.json should look like?

My take on this was

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"
      ] 
    }
  ]
}

This kind off works, but not quite. A better solution would be to always build first and then to dynamically use insert the build dir via a variable (it is vsctk7WXgnB here).

Also the application sometimes ignores my breakpoints, even if i re-build.

User12547645
  • 6,955
  • 3
  • 38
  • 69

0 Answers0