cfn-language-discussion
cfn-language-discussion copied to clipboard
Feature request for a new `Fn::Replace` intrinsic function
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Tell us about your request
What do you want us to build?
As an AWS CloudFormation template editor, I want to have a new Fn::Replace
intrinsic function so that I can search for and replace a given occurrence with another one.
Tell us about the problem you are trying to solve. What are you trying to do, and why is it hard?
What outcome are you trying to achieve, ultimately, and why is it hard/impossible to do right now?
What is the impact of not having this problem solved? The more details you can provide, the better we will be able to understand and solve the problem.
Example use case: reuse a string - such as a user-provided parameter - that holds or is related to a specific context, and transform it by replacing character(s) that are otherwise not accepted for a given property value. A sample representation of this use case is: say I describe, in a template, an AWS::CloudFormation::HookVersion
resource type, and I then reference a parameter value (e.g., My::Example::Hook
) in the TypeName
property. I also want to describe an AWS::Logs::LogGroup
resource type, that I want to reference in the LoggingConfig
property of the AWS::CloudFormation::HookVersion
resource. Now, the name of the log group cannot contain :
characters, but I'd like to create the log group in a way that still provides a contextual reference to the My::Example::Hook
input parameter value: for this, I'd like to use a new intrinsic function as in the title of this issue. Please see the "What is the expect behavior with this new feature" section for an example, proposed syntax.
Are you currently working around this issue?
How are you currently solving this problem? Whilst existing intrinsic functions would solve the example problem above, by splitting and then rejoining with different delimiters respectively, a new replace function will have the benefit of making the code more easily maintainable and readable.
What is the expect behavior with this new feature
Please include some code examples showing how this feature can be used.
Example: !Replace ["::", "_", !Ref MyTypeName]
(where !Ref MyTypeName
in this example is My::Example::Hook
- see the example use case above), so that it yields the My_Example_Hook
output that I can use as part of the log group name. The example syntax I am proposing in this example is the same syntax the Fn::If
function uses today.
Additional context
Anything else we should know? The potential replace function could also accept a regular expression pattern for the search parameter, thus making the search operation more flexible.
Attachments
If you think you might have additional information that you would like to include via an attachment, please do - we will take a look. (Remember to remove any personally-identifiable information.) Not at this time - thank you!
@mrinaudo-aws Thanks for your contribution! We'll triage and take a look at it. Stay tuned for updates!