2

I have a parameterized S3 path (different per environment) that looks something like this example:

Environment:
- Name: 'Environment'
  Value: !Ref Environment
- Name: SERVICE_LOGIN_KEYSTORE
  Value: !Sub s3://${Environment}-productsuite-cert/productsuite-pipelinename-${Environment}.jks

The issue is that the actual path has the first ${Environment} in lowercase while the second in uppercase, e.g:

s3://qa-productsuite-cert/productsuite-pipelinename-QA.jks
s3://pr-productsuite-cert/productsuite-pipelinename-PR.jks

So what I need is something like this:

!Sub s3://${Environment:Uppercase}-productsuite-cert/productsuite-pipelinename-${Environment:Lowecase}.jks
sashoalm
  • 75,001
  • 122
  • 434
  • 781

1 Answers1

3

This can be done using Fn::Transform.

See: https://github.com/awslabs/aws-cloudformation-templates/blob/master/aws/services/CloudFormation/MacrosExamples/StringFunctions/string_example.yaml

and

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-transform.html

WarrenG
  • 1,750
  • 12
  • 20
  • Thank you! Btw, what is the format, e.g. is it `!Sub s3://${Fn::Transform(Environment, Uppercase)}-productsuite-cert/productsuite-pipelinename-${Fn::Transform(Environment, Lowercase)}.jks`? – sashoalm Oct 29 '19 at 10:02
  • 1
    Hello above url yaml code is not working and gives error --> No transform named 871247504605::String found. Rollback requested by user. I have posted the question here https://stackoverflow.com/questions/59609353/aws-cloudformation-how-to-do-string-uppercase-or-lowercase-in-json-yaml-templat – Vikramsinh Gaikwad Jan 06 '20 at 09:48
  • 1
    It's not clear from the README posted, but you need to add that Python file as a transform function rather than just using the upper function. CF doesn't have any built-in support for this and you need to add your own transform function to do it. – shanet Jun 25 '20 at 00:22
  • 9
    I find this answer a little annoying. Points out the documentation, but the actual syntax/example is still not clear to me. – brendonparker Oct 14 '20 at 12:26
  • 1
    Shocking that AWS CloudFormation does not provide this out of the box. You MUST install the "macros" with a separate CF Stack. Then, via AWS Lambda the following example of using this "macro" will work: `"Fn::Transform": [{"Name": "String","Parameters": {"InputString": {"Ref": "AWS::StackName"},"Operation": "Lower"}}]` – jediwompa Mar 23 '21 at 14:55