Serverless-application-model: AutoPublishAlias not accepting !If and conditions

Created on 22 Sep 2019  路  3Comments  路  Source: aws/serverless-application-model

I'm trying to create a SAM template to use in multiple development stages.
In some stages, I have to use AutoPublishAlias (production stages); in other stages (like development or test) I don't need and I don't whant AutoPublishAlias.

But, if I use conditions to set the property

Parameters:
  DeployStack:
      Type: String

Conditions: 
  CreateProdResources: !Equals [ !Ref DeployStack, 'prod' ]

AutoPublishAlias: !If [CreateProdResources, !Ref DeployStack, !Ref AWS::NoValue]

, I have this error:

Resource with id [HelloWorldFunction] is invalid. Alias name is required to create an alias

My solution for now is to use two different SAM files, but in this project we plan to have from 40 to 60 lambda functions and can be hard to maitain.

areintrinsics-support typfeature

Most helpful comment

Thanks for reporting this! SAM doesn't support Fn::If on the AutoPublishAlias property.
Limited support for Fn::If was introduced in our last release in #988, but a little extra work is required to support it for AutoPublishAlias.

Please +1 on the feature to help with prioritization.

All 3 comments

Thanks for reporting this! SAM doesn't support Fn::If on the AutoPublishAlias property.
Limited support for Fn::If was introduced in our last release in #988, but a little extra work is required to support it for AutoPublishAlias.

Please +1 on the feature to help with prioritization.

@keetonian I also spotted this on the Enabled property of a nested event in AWS::Serverless::Function, eg.

      Events:
        1MinSchedule:
          Type: Schedule
          Description: run every 1 minute
          Properties:
            Schedule: cron(0/1 * ? * * *)
            Enabled: !Equals [!Ref DeployTypeParameter, prod]

I tried !If and !Equals (with a condition). Should I call that a dupe of this issue or open a new one?

@mcintyre94 Open a new one.

It looks to me like !Equals is not supported in CFN outside of the Conditions section of the template.

Enabled expects a boolean value, if you want to provide that via a parameter, since CFN doesn't support boolean parameter types, I think you can either pass in any string parameter to evaluate as a true value or a blank string to evaluate to false.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

voigt picture voigt  路  3Comments

yan12125 picture yan12125  路  3Comments

PMudra picture PMudra  路  4Comments

feinstein picture feinstein  路  3Comments

charsleysa picture charsleysa  路  3Comments