有没有办法来改变C $ CS亚马逊API网关返回HTTP状态$亚马逊、没有办法、网关、状态

由网友(从来馒头配咸菜〆)分享简介:举例来说,如果我想返回特定的400错误无效的参数或者一个201的时候lambda函数调用导致了创建。For instance if I want to return a specific 400 error for invalid parameters or perhaps a 201 when the lambda...

举例来说,如果我想返回特定的400错误无效的参数或者一个201的时候lambda函数调用导致了创建。

For instance if I want to return a specific 400 error for invalid parameters or perhaps a 201 when the lambda function call resulted in a create.

我想有不同的HTTP状态codeS,但它看起来像API网关总是返回200状态code,即使在lambda函数返回一个错误。

I'd like to have different http status codes but it looks like api gateway always returns a 200 status code even if the lambda function is returning an error.

推荐答案

下面是返回自定义HTTP状态codeS和一个自定义的的errorMessage 最快的方式:

Here's the fastest way to return custom HTTP Status Codes and a custom errorMessage:

在API网关仪表盘,请执行以下操作:

In the API Gateway dashboard, do the following:

在方法的为您的资源的,点击的方法响应的 在 HTTP状态的表,点击的添加响应的添加在每个HTTP状态code,你想使用。 在方法的为您的资源的,点击的集成响应的

添加的集成响应的每个HTTP状态codeS前面创建的。确保的输入直通的检查。使用的拉姆达错误的正则表达式的识别哪些状态,当你从你的lambda函数返回一个错误信息code应该使用。例如: In the method for your resource, click on method response In the HTTP Status table, click add response and add in each HTTP Status Code you would like to use. In the method for your resource, click on integration response

Add an integration response for each of the HTTP Status Codes you created earlier. Make sure input passthrough is checked. Use lambda error regex to identify which status code should be used when you return an error message from your lambda function. For example:

// Return An Error Message String In Your Lambda Function

return context.fail('Bad Request: You submitted invalid input');

// Here is what a Lambda Error Regex should look like.
// Be sure to include the period and the asterisk so any text
// after your regex is mapped to that specific HTTP Status Code

Bad Request: .*

您的API网关路由应该返回这样的:

如何让c列的名字按f列名字排序de列随c列改变顺序.具体在哪列输入哪个公式,谢谢

Your API Gateway route should return this:

HTTP Status Code: 400
JSON Error Response: 
    {
        errorMessage: "Bad Request: You submitted invalid input"
    }

我看不出有什么办法复制这些设置,并重新将其用于不同的方法,所以我们有很多烦人的冗余手动输入的事!

I see no way to copy these settings and re-use it for different methods, so we have much annoying redundant manual inputting to do!

我的积分回应是这样的:

My Integration Responses look like this:

阅读全文

相关推荐

最新文章