API 网关是否自动验证输入模型?
Does API Gateway automatically validate input model?
我在 AWS API 网关中使用以下端点创建了简单的 API:
POST /v1/users
在方法执行/方法请求中我添加了请求模型:
此模型架构如下所示:
然而,当我向带有 json 正文 { "foo": "bar" }
的端点发出请求时,它不会拒绝它并且执行了我的 lambda 函数...
那么,如果 JSON 模式不用于验证请求,为什么会有定义模式的选项?
我自己也在想办法解决这个问题,我看你几个小时前也才问过这个问题!
到目前为止,我找到的唯一参考是这里:
http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html
For non-GET method types, expand Request Models, and for Content Type and Model name, type the content type and choose the name of a model that will transform caller-supplied data into the expected format.
看来它更多的是用于转换而不是验证 - 但它实际上是如何工作的并不是特别清楚。
更新
我刚刚注意到这个 HackerNews 线程:
https://news.ycombinator.com/item?id=9880683
一位 AWS 工程师在那里回复说:
Models are not required for validation. They are simply used to generate the objects in the client SDKs.
无论如何 input/model API 网关的验证只应被视为从安全角度来看的额外防御层。
Your service MUST always validate the inputs/models it's not something
you can delegate!
此功能已于 2017 年 4 月 11 日发布。参见 https://aws.amazon.com/blogs/compute/how-to-remove-boilerplate-validation-logic-in-your-rest-apis-with-amazon-api-gateway-request-validation/
我在 AWS API 网关中使用以下端点创建了简单的 API:
POST /v1/users
在方法执行/方法请求中我添加了请求模型:
此模型架构如下所示:
然而,当我向带有 json 正文 { "foo": "bar" }
的端点发出请求时,它不会拒绝它并且执行了我的 lambda 函数...
那么,如果 JSON 模式不用于验证请求,为什么会有定义模式的选项?
我自己也在想办法解决这个问题,我看你几个小时前也才问过这个问题!
到目前为止,我找到的唯一参考是这里:
http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-method-settings.html
For non-GET method types, expand Request Models, and for Content Type and Model name, type the content type and choose the name of a model that will transform caller-supplied data into the expected format.
看来它更多的是用于转换而不是验证 - 但它实际上是如何工作的并不是特别清楚。
更新
我刚刚注意到这个 HackerNews 线程:
https://news.ycombinator.com/item?id=9880683
一位 AWS 工程师在那里回复说:
Models are not required for validation. They are simply used to generate the objects in the client SDKs.
无论如何 input/model API 网关的验证只应被视为从安全角度来看的额外防御层。
Your service MUST always validate the inputs/models it's not something you can delegate!
此功能已于 2017 年 4 月 11 日发布。参见 https://aws.amazon.com/blogs/compute/how-to-remove-boilerplate-validation-logic-in-your-rest-apis-with-amazon-api-gateway-request-validation/