validation - 如何仅使用请求在没有插件的情况下验证 AWS 无服务器架构
问题描述
我正在尝试使用正文/有效负载和参数验证发布请求:
curl -X POST \
[url]/api/{param1}/comment/{param2} \
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"bodyParam1": "45",
"bodyParam2": 123123,
"bodyParam3": 123
}
'
使用 node js 的无服务器框架。
这是我用 lambda 和 lambda-proxy 测试过的 serverless.yml,对于这两个我都无法验证参数:
functions:
someName:
handler: src/comment.post
events:
- http:
integration: lambda-proxy
path: /api/{param1}/comment/{param2}
method: post
request:
schema:
application/json: ${file(./src/models/schema1.json)}
cors: true
这是我的 schema1.json:
{
"definitions" : {},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title" :"Get object",
"required": [
"bodyParam1",
"bodyParam2",
"bodyParam3"
],
"properties": {
"bodyParam1":
{
"type":
"string"
},
"bodyParam2":
{
"type":
"integer"
},
"bodyParam3":
{
"type":
"integer"
}
}
}
请注意,这是对无服务器请求的本机支持,而不是插件版本。
解决方案
使用aws cli
:
aws cloudformation validate-template --template-body file://schema1.json
推荐阅读
- python - django 2 博客上的 ckeditor
- amazon-web-services - AppMesh 政策不可用
- javascript - ajax 调用导致适合隐藏模式
- javascript - 如何通过页面滚动修复页眉+表头和滚动表体和页脚
- recursion - 使用递归辅助函数检查素数
- php - PHP 中的 ReCaptcha v2 实现
- c# - 最大化后WinForms闪烁 - 双缓冲
- canvas - 使用 FabricJs 调整画布大小以适应图像大小和缩放
- javascript - 如何从节点模块以编程方式读取 app.json
- python - 带有误差线的 Python matplotlib 3D 条形图