Update Python Lambda debugging instructions
micholas opened this issue · 1 comments
micholas commented
Steps for VS Code on OSX
- Use pyenv to install Python 3.6 and fix path (see supported Python versions)
brew upgrade aws/tap/aws-sam-cli
sam init --runtime python3.6 --name python-debugging
cd python-debugging
- Edit:
hello_world/requirements.txt
and add the line:ptvsd
- 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')
- 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"
}
]
}
]
}
sam build
sam local invoke -d 5890 --no-event
- Debug Tab > Debug menu > SAM CLI Python Hello World
- Click green arrow
Additional recommendations
- Specify supported Python versions
- Define SAM terms for folder concepts i.e. what do we call the file containing
template.yaml
? continuing handler, code andrequirements.txt
?
joshbean commented
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.