简体   繁体   English

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

[英]How to add non authenticated routes in AWS SAM template

So this is my 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"

How can I make the path/two an non authenticated route?如何使path/two成为非认证路由? I tried to google but there was nothing.我试着用谷歌搜索,但什么也没有。

If possible I don't want to create another API Gateway.如果可能,我不想创建另一个 API 网关。 I would like to do it within the same resource.我想在同一资源内进行。

In AWS SAM template, to disable security for specific endpoints in the DefinitionBody , what worked for me is the following:在 AWS SAM 模板中,要禁用DefinitionBody中特定端点的安全性,对我有用的是以下内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM