Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Update Python Lambda debugging instructions #8

Closed
micholas opened this issue Mar 14, 2019 · 1 comment
Closed

Update Python Lambda debugging instructions #8

micholas opened this issue Mar 14, 2019 · 1 comment
Labels

Comments

@micholas
Copy link

micholas commented Mar 14, 2019

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?
@joshbean
Copy link
Contributor

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants