Missing instrinsic function for prefix matching string function (Fn::StartsWith?)
Name of the resource
Other
Resource name
AWS::CloudFormation
Description
Emulating a string prefix checking function looks like this:
Condition:
ItemStartsWith: !Equals [ !Select [ 0, !Split [ "prefix", !Ref ... ]], "" ]
like a real world use case:
Conditions:
# Starts-with macro for checking if the cluster has a custom redis host protocol
# (CacheRedisUrl may be `new:elasticache` to specify making a new cluster
HasCustomRedisUrl: !And [
!Not [ !Equals [ !Ref CacheRedisUrl, "" ]],
!Equals [ !Select [ 0, !Split [ "redis://", !Ref CacheRedisUrl ]], "" ]
]
CreateElasticCache: !Equals [!Ref CacheRedisUrl, 'new:elasticache']
OverrideRedisClusterEnvironment: !Or [ !Condition HasCustomRedisUrl, !Condition HasCustomRedisUrl]
However, Fn::Split and Fn::Select cannot be used inside any Assertions. This means that it is not possible to make rules that require a stack have a specific prefix for compliance. It is barely possible to do Fn::If statements with the above Conditions.
Other Details
An alternative approach would be to allow Fn::Split and Fn::Select on Assertions inside Rules. Or allow passing Condition: items to Rules:
I'm sure I could find uses for Fn::StartsWith, but regex support might be a more robust solution, in that it would cover not only this use case but any number of others.
I have not checked whether an issue has already been opened suggesting that.
I agree that a regex solution would also be helpful. I do understand the reluctance to add multiple functions, even if it does make exceedingly common string operations a little easier.
in either case, a startswith or a regex would be exceptionally helpful, especially in the Assertion Rules and Conditions.