我试图在Visual代码中本地调试模板。
在没有导入requirements.txt中提到的任何模块时,我成功地做到了这一点
My.vscode/unch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "aws-sam",
"request": "direct-invoke",
"name": "Invoke Lambda",
"invokeTarget": {
"target": "code",
"lambdaHandler": "hello_world/app.lambda_handler",
"projectRoot": "${workspaceFolder}"
},
"lambda": {
"runtime": "python3.9",
"payload": {
"json": {}
}
}
}
]
}我的hello_world/app.py
import json
import requests
def lambda_handler(event, context):
print('hello')
return {
"statusCode": 200,
"body": json.dumps({
"message": "hello world",
# "location": ip.text.replace("\n", "")
}),
}在注释掉import requests之后,我能够用断点成功地调试它。
为了确定,我尝试执行sam build并检查生成的..aws sam文件夹。它确实在..aws sam/build/HelloWorldFunction文件夹下下载了请求模块。
sam local invoke工作时没有任何导入错误。
项目结构:
.aws-sam \
build \
HelloWorldFunction \
modules*
app.py
template.yaml
build.toml
.vscode \
launch.json
events \
event.json
hello_world \
__init__.py
app.py
requirements.txt
tests \
...
__init__.py
...
template.yaml我做错了什么?
发布于 2022-03-07 09:37:19
显然,调试器在您提到的requirements.txt文件夹中寻找launch.json中的projectRoot
将requirements.txt从{projectroot} / hello-world复制到{projectroot}修复了这个问题
https://stackoverflow.com/questions/71378866
复制相似问题