Reputation: 19339
In my serverless.yml script which uses CloudFormation syntax I have defined a name for my app using the appName
variable:
custom:
appName: my-app-name
Somewhere down the script I use this appName
variable to assemble the url path string, such as:
myEndpoint:
events:
- http:
path: /${{self:custom.appName}}/index
which will result to a path
being /my-app-name/index
But I would like to replace the -
characters with _
dashes.
What would be the cleanest way of doing it?
Upvotes: 3
Views: 2217
Reputation: 31
You can use split and join functions. First, Fn::split your string using the original character, which is "-" in your case, and then Fn::Join back all values from the list returned by Fn::Split with the desired character "_".
{"Fn::Join": ["_", { "Fn::Split" : ["-", {"Ref": "myVar"}]}]}
Upvotes: 3
Reputation: 238339
You can't do this with plain CloudFormation. You have to use macros, though a custom resource could also be used. Specifically, you can use Replace
macro developed my AWS and available at aws-cloudformation /
aws-cloudformation-macros. You can also develop your own macros, or modified the one given by AWS as it is open sourced.
Upvotes: 2