我想通过无服务器设置API网关的请求验证器。我为请求验证程序尝试了两种不同的设置。但是,这两种方法都失败了。我已经总结了我所做的事情,所以请告诉我是否有问题。
sls deploy
和swagger.yaml
下面的serverless.yml
之后,x-amazon-apigateway-request-validators
中描述的所有验证模式均未添加到“请求验证器”选项中。
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validator.html swagger.yaml
在下面:
openapi: 3.0.0
info:
description: xxx
version: '0.1'
title: xxx API
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true,
validateRequestParameters: false
except-body:
validateRequestBody: false,
validateRequestParameters: true
all:
validateRequestBody: true,
validateRequestParameters: true
tags:
- name: auth
description: xxx
paths:
/login:
post:
tags:
- auth
summary: xxx
description: ''
x-amazon-apigateway-request-validator: all
responses:
'200':
description: success
content:
application/json:
schema:
$ref: '#/components/schemas/AuthResponse'
'400':
description: fail
content:
application/json
'401':
description: fail
content:
application/json
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AuthRequest'
required: true
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
uri: "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:xxx-api-dev-login/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws_proxy"
我的serverless.yml
在下面:
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
LoginApiToInvokeLambda:
Type: AWS::Lambda::Permission
DependsOn: LoginLambdaFunction
Properties:
FunctionName: xxx-ext-api-dev-login
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
AWS::ApiGateway::RequestValidator
实现请求验证程序的设置。在使用上方sls deploy
和下方swagger.yaml
进行serverless.yml
之后,all
的{{1}}中描述的RequestValidatorAll
被添加到了请求验证器选项中。但是,请求验证程序的默认值仍为NONE。
severless.yml