amazon-web-servicesaws-api-gatewayamazon-cognitoaws-sam

How to add non authenticated routes in AWS SAM template


So this is my SAM template:

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? I tried to google but there was nothing.

If possible I don't want to create another API Gateway. I would like to do it within the same resource.


Solution

  • In AWS SAM template, to disable security for specific endpoints in the DefinitionBody, what worked for me is the following:

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