【发布时间】:2021-02-23 03:26:34
【问题描述】:
我在尝试本地调试 AWS Lamda (python 3.8) 时遇到问题。从终端执行时,AWS SAM Cli 命令运行良好。但是,在尝试从 vscode 调试或构建时,它会引发错误。似乎 vscode 正在为 python 3.8 版本选择不同的路径。
这是来自终端的配置路径快照:
mbp$ which python
/usr/bin/python
mbp$ which python3
/usr/local/opt/python@3.8/bin/python3
mbp$ which aws
/usr/local/bin/aws
mbp$ which sam
/usr/local/bin/sam
mbp$ python --version
Python 2.7.16
mbp$ python3 --version
Python 3.8.8
这是视觉工作室代码日志:
2021-02-22 20:53:24 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 20:53:24 [INFO]: Building SAM application...
2021-02-22 20:53:24 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctklNIOzG/output --template /Users/mb/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctklNIOzG/debug-requirements.txt]
2021-02-22 20:53:24 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 20:53:24 [INFO]: Starting SAM application locally
2021-02-22 20:53:24 [INFO]: AWS.running.command
2021-02-22 20:53:24 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 20:53:24 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 20:53:24 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 20:53:24 [INFO]: Waiting for SAM application to start...
2021-02-22 20:53:24 [INFO]: Attaching debugger to SAM application...
2021-02-22 20:53:41 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 20:53:41 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
2021-02-22 21:56:05 [INFO]: Preparing to debug locally: Lambda "transactions.lambda_handler"
2021-02-22 21:56:05 [INFO]: Building SAM application...
2021-02-22 21:56:05 [INFO]: Running command: (not started) [/Library/Frameworks/Python.framework/Versions/3.8/bin/sam build --build-dir /tmp/aws-toolkit-vscode/vsctkIy5kkF/output --template /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml --manifest /tmp/aws-toolkit-vscode/vsctkIy5kkF/debug-requirements.txt]
2021-02-22 21:56:05 [WARN]: "sam build" failed: /Users/mbp/REPO/wisyz-transactions/app___vsctk___template.yaml
2021-02-22 21:56:05 [INFO]: Starting SAM application locally
2021-02-22 21:56:05 [INFO]: AWS.running.command
2021-02-22 21:56:05 [ERROR]: Error running command "sam local invoke": spawn /Library/Frameworks/Python.framework/Versions/3.8/bin/sam ENOENT
2021-02-22 21:56:05 [ERROR]: Timeout while waiting for command: "sam local invoke"
2021-02-22 21:56:05 [ERROR]: Failed to run SAM application locally: Timeout while waiting for command: "sam local invoke"
Command stopped: "sam local invoke"
2021-02-22 21:56:05 [INFO]: Waiting for SAM application to start...
2021-02-22 21:56:05 [INFO]: Attaching debugger to SAM application...
2021-02-22 21:57:04 [ERROR]: Retry limit reached while trying to attach the debugger.
2021-02-22 21:57:04 [ERROR]: Unable to attach Debugger. Check AWS Toolkit logs. If it took longer than expected to start, you can still attach.
【问题讨论】:
-
操作系统:mac Catalina 10.15.4
-
python3 --version和python --version的输出是什么?您使用的是 virtualenv 还是 venv? -
在原帖中添加。我也没有使用 virtualenv 或 venv
-
似乎 vscode 正在寻找 /Library/Frameworks/Python.framework/Versions/3.8/bin/sam 路径,但它不存在。不知道为什么 vscode 在该路径上查找 sam cli。
标签: python python-3.x amazon-web-services visual-studio-code aws-lambda