Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoPublishAlias not accepting !If and conditions #1154

Closed
angustohrallegrinski opened this issue Sep 22, 2019 · 6 comments
Closed

AutoPublishAlias not accepting !If and conditions #1154

angustohrallegrinski opened this issue Sep 22, 2019 · 6 comments
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature

Comments

@angustohrallegrinski
Copy link

angustohrallegrinski commented Sep 22, 2019

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.

@keetonian keetonian added area/intrinsics Ref, If, Sub, GetAtt, ... type/feature labels Sep 27, 2019
@keetonian
Copy link
Contributor

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.

@mcintyre94
Copy link

@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?

@keetonian
Copy link
Contributor

@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.

@DanielWsk
Copy link

I am still having the same issue 3 years later. I don't know why this issue got closed... It doesn't seem to be fixed.

I think implementing a way to use conditionals in a SAM template should be a basic function that is supported. smh

@hoffa
Copy link
Contributor

hoffa commented Oct 17, 2022

You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31

AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

See #2533 for more information.

@hoffa
Copy link
Contributor

hoffa commented Nov 3, 2022

Closing in favor of #2533.

@hoffa hoffa closed this as completed Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/intrinsics Ref, If, Sub, GetAtt, ... type/feature
Projects
None yet
Development

No branches or pull requests

6 participants