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:
- 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"
- 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.
Description:
In the
AWS::Serverless::Apiresource 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:
sam validateObserved result:
Expected result:
Template is considered as valid and can be deployed with optional parameter
ExternalAuthorizerArnset to either empty string or to the specific value.