如何在 AWS SAM 模板中添加未经身份验证的路由

How to add non authenticated routes in AWS SAM template

这是我的 SAM 模板:

webApi:
    Type: AWS::Serverless::Api
    Properties:
      Auth:
        DefaultAuthorizer: CognitoAuthorizer
        Authorizers:
          CognitoAuthorizer:
            UserPoolArn: !GetAtt myUserPool.Arn
        AddDefaultAuthorizerToCorsPreflight: false
      Cors:
        AllowMethods: "'*'"
        AllowHeaders: "'*'"
        AllowOrigin: "'*'"
      StageName: !Ref Environment
      DefinitionBody:
        swagger: "2.0"
        info:
          title:
            Ref: AWS::StackName
        paths:
        /path/one:
            post:
              responses: {}
              x-amazon-apigateway-integration:
                uri: myFunction.Arn
                httpMethod: "POST"
                type: "aws_proxy"
          /path/two:
            post:
              responses: {}
              x-amazon-apigateway-integration:
                uri: myFunction.Arn
                httpMethod: "POST"
                type: "aws_proxy"

如何使 path/two 成为非认证路由? 我试过 google 但什么也没有。

如果可能,我不想创建另一个 API 网关。我想在同一资源内进行。

作为 OpenAPI,您可以使用 security: [] 禁用某些路径中的身份验证。

参考:

https://github.com/zalando/connexion/issues/944 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body

在 AWS SAM 模板中,要禁用 DefinitionBody 中特定端点的安全性,对我有用的是以下内容:

 swagger: "2.0"
        info:
          title:
            Ref: AWS::StackName
        paths:
          /path/one:
            post:
              security:
                - NONE: []