问题描述
我已经通过使用无服务器框架部署的lambda函数配置了API网关.我已经定义了一些queryStringParameters在yaml文件中为true.但是,即使没有在URL中传递Required(强制性)queryStringParams,请求仍通过服务传递.PFB的配置类似.
I've configured API gateway via lambda function deployed with serverless framework. I've defined some queryStringParameters to be true in the yaml file. But the request is passing through the service even when the Required(mandatory) queryStringParams are not passed in URL. PFB the similar config.
功能:functionName:名称:serviceName处理程序:handler.handle事件:-http:路径:/path方法:获取要求:参数:查询字串:param1:trueparam2:true
似乎无服务器无法验证param1和param2是否作为queryString传递.我们应该有一个明确的请求验证器吗?使用Serverless可以做到吗?
Seems serverless is not validating whether param1 and param2 are passed as queryString. Should we have an explicit Request validator?. Is it possible to do so with Serverless?
推荐答案
对于像我一样也看不到的那些人.
For those of you failing to see this, like I also did.
这就是你需要用简单的英语做的事情.
This is what you need to do in plain english.
打开
ApiGatewayMethodNameOfYourApiLookItUpInYourTemplate
ApiGatewayMethodNameOfYourApiLookItUpInYourTemplate
到
APIGatewayMethod< 1>< 2>
APIGatewayMethod<1><2>
在我的情况下,这是APIGatewayDealsGet
In my case, it was APIGatewayDealsGet
我正在查看的是我在无服务器环境中的处理程序名称
The thing I was looking at was my handler name in serverless
list:
# Defines an HTTP API endpoint that calls the main function in list.js
# - path: url path is /deals
# - method: GET request
handler: list.main
events:
- http:
path: deals
method: get
cors: true
authorizer: aws_iam
request:
parameters:
querystrings:
country: true
type: true
或者,如果这不起作用,请检查s3存储桶,将其命名为xxxxxxx-ap-serverlessdeploymentbuck-1epdp60eqveqr并转到无服务器>yyyyyyyyyy>aaaa>时间戳>编译cloudformation-template.json
Alternatively, if this does not work, check the s3 bucket, mine was called xxxxxxx-ap-serverlessdeploymentbuck-1epdp60eqveqr and go to serverless > yyyyyyyyyyy > aaaa >timestamp > compiled-cloudformation-template.json
然后在其中查找您的方法的名称,示例示例为:
And look for the name of your method in there, example mine was:
"ApiGatewayMethodDealsGet": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"RequestParameters": {
这篇关于即使在无服务器yaml中设置了必需的参数后,QueryString参数也没有得到验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!