Skip to content

Fn::If intrinsic function inside Auth property of "AWS::Serverless::Api" #1859

@maslakov

Description

@maslakov

Description:

In the AWS::Serverless::Api resource I want to specify optional authorizer. For this purpose I try to use Conditions and "!If" intrinsic function. SAM doees not consider such a template as a valid one. I tried already all combinations with "!If" and "Fn::If" and indentation - it does not work.

Steps to reproduce the issue:

  1. Create new template with the following content
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  Sample SAM Template for test

Parameters:
  ExternalAuthorizerArn:
    Type: String

Conditions:
  ExternalAuthorizer: !Not [!Equals [ !Ref ExternalAuthorizerArn, '' ]]

Resources:

  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Test
      Auth:
        ApiKeyRequired: false
        Fn::If:
        - ExternalAuthorizer
        -
          Authorizers:
            ApiKeyAuth:
              FunctionPayloadType: TOKEN
              FunctionArn: !Ref ExternalAuthorizerArn
              Identity:
                Header: x-api-key
                ReauthorizeEvery: 300
        - !Ref "AWS::NoValue"
  1. try to deploy or just validate it:

sam validate

Observed result:

Template provided at '/Users/xxx/tmp/test/template.yaml' was invalid SAM Template.
Error: [InvalidResourceException('ApiGatewayApi', "Invalid value for 'Auth' property")] ('ApiGatewayApi', "Invalid value for 'Auth' property")

Expected result:

Template is considered as valid and can be deployed with optional parameter ExternalAuthorizerArn set to either empty string or to the specific value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/intrinsicsRef, If, Sub, GetAtt, ...stage/pm-reviewWaiting for review by our Product Manager, please don't work on this yettype/feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions