aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap

Missing instrinsic function for prefix matching string function (Fn::StartsWith?)

Open
#1,260 2 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
1.1k
Forks
62
PR merge metrics
No merged PRs in 30d

Description

### 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 `Assertion`s inside `Rules`. Or allow passing `Condition:` items to `Rules:`

Contributor guide

Open the contributing guide

Research direction

Review the AWS::CloudFormation Rules section, especially Assertions and the documented restrictions on Fn::Split and Fn::Select. Compare the requested Fn::StartsWith function with the alternatives of permitting those intrinsics or Condition items in Rules. Done means the supported approach is defined and the prefix-compliance use case can be expressed.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws
Domain
cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.