使用API Gateway处理AWS Lambda函数中的错误 [英] Handling errors in AWS Lambda function with API Gateway
本文介绍了使用API Gateway处理AWS Lambda函数中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每次我遇到语法错误,或者我只想在AWS Lambda函数中发送自定义错误时,都会收到相同的502 Bad Gateway响应(内部服务器错误).
Every time I have a syntax error or I just want to send a custom error in my AWS Lambda function, I get the same 502 Bad Gateway response (Internal server error).
我尝试了简单的代码:
module.exports.saveImage = (event, context, callback) => {
callback("the sky is falling!"); // also tried sending new Error("the sky is falling!")
}
并且仍然收到相同的内部服务器错误"响应,而不是已定义的响应.
And still getting the same "Internal server error" response instead of the defined one.
这是我在serverless.yml文件中的功能:
This is my function in the serverless.yml file:
saveImage:
handler: handler.saveImage
environment:
BUCKET: ${self:custom.bucket}
events:
- http:
path: saveImage
method: post
cors: true,
integration: lambda-proxy
我是否可能误解了这篇文章中的某些内容?似乎收到了"errorMessage":天塌了!"在API网关响应中(这就是我所期望的).
May I have misunderstood something from this article? It seems to recieve the "errorMessage": "the sky is falling!" in the API Gateway response (and that's what I would expect).
查看全文