0

我们有一个 lambda 部署到 Localstack,API 网关端点配置为 AWS_PROXY。如果正文为空或包含 JSON,则使用 POST 调用 Lambda 有效,但是,在正文中发送 XML(不管 Content-Type)总是返回 502。Localstack 日志中的错误是:

localstack_1  | 2019-11-14T13:29:49:ERROR:localstack.services.generic_proxy: Error forwarding request: Expecting value: line 1 column 1 (char 0) Traceback (most recent call last):
localstack_1  |   File "/opt/code/localstack/localstack/services/generic_proxy.py", line 240, in forward
localstack_1  |     path=path, data=data, headers=forward_headers)
localstack_1  |   File "/opt/code/localstack/localstack/services/apigateway/apigateway_listener.py", line 35, in forward_request
localstack_1  |     data = data and json.loads(to_str(data))
localstack_1  |   File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
localstack_1  |     return _default_decoder.decode(s)
localstack_1  |   File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
localstack_1  |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
localstack_1  |   File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
localstack_1  |     raise JSONDecodeError("Expecting value", s, err.value) from None
localstack_1  | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我认为 AWS_PROXY 集成应该直接将数据传递给 Lambda 而不尝试解码或验证?有没有办法设置 API 网关集成,以便它愉快地接受 XML?

这是我们在部署 lambda 后用于设置 API 网关的函数:https ://gist.github.com/jgwconsulting/0c5597a661cbc6d29aaa346b2aed5020

4

1 回答 1

0

这似乎是 Localstack 总是假设 POST 数据将是 JSON 并尝试将其解析为 Python 字典的问题。

我在这里创建了一个问题来跟踪问题,如果有时间,我会尝试进行 PR 来修复它:https ://github.com/localstack/localstack/issues/1762

于 2019-11-14T16:28:49.533 回答