【发布时间】:2017-09-07 00:25:46
【问题描述】:
我正在构建一个 AWS API 邮件服务,它基本上会在发送包含来自该正文的数据的邮件之前检查请求的正文。它检查是否存在每个必需的参数,并进行一些基本检查数据是否符合我们的要求。
问题是,即使 Lambda 函数抛出错误(我使用 Lambda 测试接口进行了验证),API 网关也会返回一个 200 响应代码以错误对象为主体
这意味着我得到了这样的日志:
Tue Apr 11 14:23:43 UTC 2017 : Method response body after transformations:
{"errorMessage":"\"[BadRequest] Missing email\""}
Tue Apr 11 14:23:43 UTC 2017 : Method response headers: {X-Amzn-Trace-Id=Root=************, Content-Type=application/json}
Tue Apr 11 14:23:43 UTC 2017 : Successfully completed execution
Tue Apr 11 14:23:43 UTC 2017 : Method completed with status: 200
由于最后一部分,我相信 API Gateway 正在返回 200。
我做了几件事来设置错误处理:
此时我不确定为什么它仍然无法返回正确的响应。我查看了有关此的各种帖子(包括:Is there a way to change the http status codes returned by Amazon API Gateway? 和 How to return error collection/object from AWS Lambda function and map to AWS API Gateway response code)并阅读了文档。
我也尝试了“Lambda 代理方式”,但没有产生任何结果(lambda 根本没有正确执行这种方式”。
有人看到我在这里缺少什么吗?
【问题讨论】:
标签: amazon-web-services aws-lambda aws-api-gateway