我有一个带有 Python 处理程序的 Lambda 设置,我已经创建了一个 API 端点来仅接收 POST 方法。我想不通的是我的 Lambda 应该如何告诉 API 网关事情已经成功完成并返回 HTTP 200 状态代码。有没有人冒险走这条路?
最佳答案
在 python lambda 中做
raise Exception('notfound')
使用任何其他关键字代替 notfound。
然后在 apigateway 中,您需要将 'notfound'
映射到一些响应状态代码。我为此使用了 swagger,所以这里是如何跟踪 'notfound'
的示例:
"/tags/getById": {
"get": {
"summary": "Find the tag by it's ID",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "successful operation",
"schema": {
"$ref": "#/definitions/Tag"
}
},
"404": {
"description": "No tag found"
}
},
"parameters": [xxxxxxx],
"x-amazon-apigateway-integration": {
"requestTemplates": {xxxxx},
"uri": {xxxxxx},
"responses": {
"default": {
"statusCode": "200"
},
"notfound": {
"statusCode": "404"
}
},
"httpMethod": "POST",
"type": "aws"
}
}
}
关于amazon-web-services - 通过 API 网关从 Lambda 返回 HTTP 状态代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33384664/