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

时间:2019-11-28 07:04:39

标签: amazon-web-services aws-api-gateway amazon-cognito aws-sam

这是我的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网关。我想在同一资源内完成此操作。

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

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

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