1

我正在尝试使用 SAM(python3.8)构建一个 lambda 函数。我在 VSCode 上安装了 AWS 工具包并创建了 hello_world 函数。SAM 构建成功完成。当我使用预定义的 test/events/event.json运行调用命令时,出现异常:

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

你能指导我如何解决这个问题吗?

4

1 回答 1

2

你应该提供你的 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))
于 2021-08-11T14:47:17.943 回答