Cloudformation remove dashes from parameters

Viewed 2256

I'm trying to run a nested stack with the root stack that creates multiple resources including S3 buckets and a Cognito User Pool. The issue is:

  • S3 bucket name doesn't allow Capitalised letters.
  • Cognito Identity Pool name doesn't allow dashes -.

I want to name my resources with the same/similar name ${AWS::StackName}-then-some-string so they're recognised as parts of one application.

Is there a way to remove dashes from parameters inside cloudformation? I know I can use Fn::Split to split the string with - then use Fn::Select to select specific elements then Fn::Join but that will only work for a stack name with a certain amount of dashes -.

I can't find any resource anywhere on how to change the - to empty string or something else using some sort of function or regex.

1 Answers

You're nearly there - use Fn::Split and Fn::Join, no select needed.

SomeKey:
  Fn::Join:
  - ''
  - Fn::Split:
    - '-'
    - !Ref YourParam

Split returns an array. Join takes a join string and an array of items to join. So just split on the hyphen/dash, then join the parts back together with an empty string, thereby eliminating the hyphens.

Related