sumek
sumek

Reputation: 28172

CloudFormation Transform inside FindInMap

I'm trying to Transform one of the keys passed to FindInMap. The example I was trying to follow comes from here:

https://github.com/awslabs/aws-cloudformation-templates/tree/master/aws/services/CloudFormation/MacrosExamples/StringFunctions/#basic-usage

        - Fn::FindInMap
          - 'Fn::Transform':
               Name: 'String'
               Parameters:
                  InputString: !Ref Env
                  Operation:
                    Replace:
                      Old: "-"
                      New: ""
          - !Ref "AWS::Region"
          - 'AppSubnetIds'

I'm getting following error message as the response:

mapping values are not allowed here
  in "<unicode string>", line 186, column 28:
              - 'Fn::Transform':
                               ^ (line: 186)

Is the problem with my syntax? Or is the generally not possible?

Upvotes: 0

Views: 247

Answers (1)

berenbums
berenbums

Reputation: 1354

This is a syntax error. One example how it should be for the Replace operation is given in the repository. Here is a template that I was able to deploy, it uses Transform inside FindInMap and creates an S3 bucket with a test-key:test-value tag:

Parameters:
  Env:
    Type: String
    Default: env-dev

Mappings:
  envdev:
    us-east-1:
      AppSubnetIds: test-value

Resources:
  S3Bucket:
    Type: "AWS::S3::Bucket"
    Properties:
      Tags:
        - Key: test-key
          Value: 
            'Fn::FindInMap':
              - 'Fn::Transform':
                   Name: 'String'
                   Parameters:
                      InputString: !Ref Env
                      Operation: Replace
                      Old: "-"
                      New: ""
              - !Ref "AWS::Region"
              - AppSubnetIds

Upvotes: 1

Related Questions