【发布时间】:2018-02-15 13:34:15
【问题描述】:
手头的问题:仅在访问事件数据时出现格式错误的 Lambda 异常。
当我访问该事件时,API Gateway 返回“内部服务器错误”。 我想做的事情的一个简化用例是访问从 POST 请求中提供给 Lambda 的键的值,使用代理集成,因此不需要模板映射。
import json
def lambda_handler(event, context):
items = {}
items["hello"] = "name"
itemsarray = []
for key, value in event.items() :
itemsarray.append(key + ":" + value)
return {
'statusCode': 200,
'isBase64Encoded': False,
'body' : json.dumps(items),
'headers': {
'content-type': 'application/json'
}
};
来自 API Gateway 的错误消息,Lambda 本身没有返回代码错误。
Thu Feb 15 13:24:51 UTC 2018 : Received response. Integration latency: 742 ms
Thu Feb 15 13:24:51 UTC 2018 : Endpoint response body before transformations: {"errorMessage": "must be str, not NoneType", "errorType": "TypeError", "stackTrace": [["/var/task/lambda_function.py", 9, "lambda_handler", "itemsarray.append(key + \":\" + value)"]]}
Thu Feb 15 13:24:51 UTC 2018 : Execution failed due to configuration error: Malformed Lambda proxy response
Thu Feb 15 13:24:51 UTC 2018 : Method completed with status: 502
JSON 发布数据
{ "dummy": "hello", "data": "world" }
【问题讨论】:
标签: python-3.x amazon-web-services aws-lambda