serverless-application-model
serverless-application-model copied to clipboard
AutoPublishAlias not accepting !If and conditions
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.
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.
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
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 Transform
s are run.
See https://github.com/aws/serverless-application-model/issues/2533 for more information.
Closing in favor of https://github.com/aws/serverless-application-model/issues/2533.