I have CloudFormation template where i have one parameter passed from previous step with value like this:
"test1.example.org"
"example.org"
"org"
Now I want to basically remove the .org part from that parameter and get:
test1.example
example
There can be many subdomain as well like
test1.test2.test3.test4.example.org
I just need to remove .org from the end
With a caveats you can achieve what you want - assuming that .org
will appear only on the end of your string.
Here's a complete template test.cfn.yaml
that shows this method working:
AWSTemplateFormatVersion: 2010-09-09
Parameters:
Input:
Type: String
Resources:
DummyBucket:
Type: AWS::S3::Bucket
Outputs:
TheOutput:
Value: !Join [ '', !Split [ '.org', !Ref Input ] ]
You can test this out with the AWS CLI by running:
aws cloudformation deploy --template-file test.cfn.yaml --stack-name test1 --parameter-overrides Input=apples.bananas.org
The output of this stack will contain apples.bananas
.
Within your script you can use !Join [ '', !Split [ '.org', !Ref Input ] ]
to strip down your string as you wanted, replacing Input with the value you need changed.
Note that there is a DummyBucket
in the stack as you need to have at least one resource for CloudFormation to deploy the script.
If I am understanding your query correctly, one way you could do it is you could use Fn::Split
function to split the string by colon and use the array element that you want to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With