awsdocs/aws-sam-developer-guide

Update Python Lambda debugging instructions

micholas opened this issue · 1 comments

https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-debugging-python.html#serverless-sam-cli-using-debugging-python-ptvsd

Steps for VS Code on OSX

  1. Use pyenv to install Python 3.6 and fix path (see supported Python versions)
  2. brew upgrade aws/tap/aws-sam-cli
  3. sam init --runtime python3.6 --name python-debugging
  4. cd python-debugging
  5. Edit: hello_world/requirements.txt and add the line: ptvsd
  6. Update hello_world/app.py add the following code after the last import
import ptvsd
print('waiting for debugger... you should start it now')
# Enable ptvsd on 0.0.0.0 address and on port 5890 that we'll connect later with our IDE
ptvsd.enable_attach(address=('0.0.0.0', 5890), redirect_output=True)
ptvsd.wait_for_attach()
print('debugger attached')
  1. Debug Tab > Debug menu > Add configuration
    "version": "0.2.0",
    "configurations": [
        

        {
           "name": "SAM CLI Python Hello World",
           "type": "python",
           "request": "attach",
           "port": 5890,
           "host": "localhost",
           "pathMappings": [
               {
                   "localRoot": "${workspaceFolder}/hello_world",
                   "remoteRoot": "/var/task"
               }
           ]
       }
   ]
 }
  1. sam build
  2. sam local invoke -d 5890 --no-event
  3. Debug Tab > Debug menu > SAM CLI Python Hello World
  4. Click green arrow

Additional recommendations

  1. Specify supported Python versions
  2. Define SAM terms for folder concepts i.e. what do we call the file containing template.yaml? continuing handler, code and requirements.txt?

Closing this issue or pull request in advance of archiving this repo. For more information about the decision to archive this repo (and others in the "awsdocs" org), see the announcement on the AWS News Blog.