我正在尝试使用 SAM (python3.8) 构建一个 lambda 函数。 我在 VSCode 上安装了 AWS 工具包并创建了 hello_world 函数。 SAM 构建成功完成。 当我使用预定义的 test/events/event.json 运行 invoke 命令时,出现异常:
sam local invoke "TestFunction" -e test/events/event.json
输出:
{"errorMessage": "Unable to unmarshal input: Expecting value: line 1 column 1 (char 0)", "errorType": "Runtime.UnmarshalError", "stackTrace": []}
在没有事件的情况下运行时,该函数不会引发任何错误。
版本:
- SAM CLI,版本 1.23.0
- aws-cli/1.18.69 Python/3.8.5 Linux/5.8.0-53-generic botocore/1.16.19
- Docker 版本 20.10.6,内部版本 370c289
您能指导我如何解决这个问题吗?
最佳答案
您应该提供您的 Python 代码来查看问题到底是什么。
但我猜问题出在 requests.post
调用上。
而不是:
requests.post(url, headers=headers, data=json_data)
尝试:
requests.post(url, headers=headers, json=json_data)
# Or
requests.post(url, headers=headers, data=json.dumps(json_data))
关于python - AWS SAM : Unable to unmarshal input,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67724558/