Developing lambdas - AWS SAM with VSCode and Linux: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
Line 113: Line 113:
. ~/.ssh-agent
. ~/.ssh-agent
</syntaxhighlight>
</syntaxhighlight>
== Debugging lambda ==
For debugging Lambda I use Visual Studio Code with Remote SSH plug-in and [https://aws.amazon.com/serverless/sam/ AWS SAM] - you should install it first. Once you will install AWS SAM it is necessary to update Visual Studio Code launch configuration. Launch configuration map path between docker image code (AWS SAM) and VS Code. Path is relative the file you want to debug has to be opened.
=== VS Code Launch configuration ===
<syntaxhighlight lang="bash">
{
    "version": "0.2.0",
    "configurations": [
        {
          "name": "SAM CLI Python Hello World",
          "type": "python",
          "request": "attach",
          "port": 5890,
          "host": "localhost",
          "pathMappings": [
              {
                 
                  "localRoot": "${fileDirname}",
                  "remoteRoot": "/var/task"
              }
          ]
      }
  ]
}
</syntaxhighlight>
=== Add to Python code ===
<syntaxhighlight lang="python">
import ptvsd
print("Waiting for attach on port 5890")
ptvsd.enable_attach(address=('0.0.0.0', 5890), redirect_output=True)
ptvsd.wait_for_attach()
</syntaxhighlight>
=== Invoke ===
<syntaxhighlight lang="bash">
sam local invoke --profile default --region us-east-1  NameOfApp -d 5890
</syntaxhighlight>
=== Debugging ===
Once you open a file which you want to debug, add python code for debug, launch "sam local invoke" and click on debugging icon in VS Code. If you have your breakpoints selected you should be fine. Only thing which does not worked correctly for me is stopping on uncaught exceptions - [https://github.com/awslabs/serverless-application-model/issues/1613 Ticket I opened with AWS, still unresolved]

Navigation menu