How to add non authenticated routes in AWS SAM template
Asked Answered
D

2

0

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.

Dogear answered 28/11, 2019 at 7:4 Comment(0)
D
4

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: []
Dogear answered 9/12, 2019 at 1:26 Comment(0)
G
3

As OpenAPI, you can use security: [] to disable auth in some path.

Refer:

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

Grandioso answered 28/11, 2019 at 7:26 Comment(1)
Ok I have tried this solution but it did not work, instead this worked: security: - NONE: []Dogear

© 2022 - 2024 — McMap. All rights reserved.