gpt4 book ai didi

amazon-web-services - 如何在 AWS::Serverless::Api 的 AWS SAM 模板中添加请求验证器?

转载 作者:行者123 更新时间:2023-12-03 14:38:46 24 4
gpt4 key购买 nike

我正在尝试使用 AWS SAM 将请求验证器资源链接到 SAM 模板中的无服务器 API。我已经创建了请求验证器并在其 RestApiId 中引用了 API,但验证器没有被设置为 AWS 控制台中的 API 默认验证器选项。

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Discription for the template
Globals:
Function:
Timeout: 30

Resources:
MyAPI:
Type: AWS::Serverless::Api
Properties:
Name: MyAPI
StageName: prod
Auth:
DefaultAuthorizer: MyAuthorizer
Authorizers:
MyAuthorizer:
FunctionPayloadType: REQUEST
FunctionArn: here goes the function Arn
Identity:
Context:
- identity.sourceIp
ReauthorizeEvery: 60
Models:
RequestModel:
$schema: 'http://json-schema.org/draft-04/mySchema#'
type: object
properties:
Format:
type: string
Name:
type: string
minLength: 3
Id:
type: string
required:
- Format
- Id

RequestValidator:
Type: AWS::ApiGateway::RequestValidator
Properties:
Name: RequestValidator
RestApiId: !Ref MyAPI
ValidateRequestBody: true

LambdaFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: NameOfTheFunction
CodeUri: ./src/folder/
Handler: Project::nameSpace.class::Handler
Runtime: dotnetcore2.1
Environment:
Variables:
variableA : value
variableB : value
variableC : value
variableD : value
Events:
ApiEndpoint:
Type: Api
Properties:
RestApiId: !Ref MyAPI
Path: /path
Method: post
RequestValidatorId: !Ref RequestValidator
Auth:
Authorizer: MyAuthorizer
RequestModel:
Model: RequestModel
Required: true

验证器被创建,如果我点击 API 上的请求验证器下拉菜单,我可以看到它。但是,请求验证器并不默认为我定义的验证器。它只是将 None 作为选定的选项

最佳答案

我搜索了 api 转换函数的源代码,但没有办法附加请求验证。 SAM 将 AWS::Serverless::Api 转换为内联正文 swagger/openapi 定义,但对于 x-amazon-apigateway-request-validator 没有任何内容。我不明白为什么有办法在 lambda 事件中定义模型,因为它只在 api 方法中附加模式部分

"paths": {
"/post": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/user"
}
}
},
"required": true
},

也许在 SAM github 中添加功能请求

关于amazon-web-services - 如何在 AWS::Serverless::Api 的 AWS SAM 模板中添加请求验证器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57860631/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com