通过API Gateway从Lambda返回HTTP状态码

3

我在Lambda中设置了一个Python处理程序,并创建了一个API端点,仅接收POST方法。但我无法弄清楚Lambda应该如何告诉API Gateway任务已成功完成并返回HTTP 200状态码。有人尝试过这条路吗?

3个回答

1
在Python中,lambda就是这样做的。
raise Exception('notfound')

不要使用“未找到”关键字,选择其他关键字。

然后在 API 网关中,需要将'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"
            }
          }
       }

0

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接