Michael Coxon
Michael Coxon

Reputation: 3535

Template format error: Every Mappings attribute must be a String or a List

I wanted to have some quick references at the top of my CloudFormation template, so that I don't have to write out a complex reference every time i need it throughout the template.

So I wrote this:

Mappings:
  StandardResourcesMap:
    AWSExecuteApi:
      string: !Join [ ':' , ['arn', !Sub '${AWS::Partition}', 'execute-api', !Sub '${AWS::Region}', !Sub '${AWS::AccountId}'] ]
    AWSLambdaFunctions:
      string: !Join [ ':' , ['arn', !Sub '${AWS::Partition}', 'apigateway', !Sub '${AWS::Region}', 'lambda:path/2015-03-31/functions/'] ]

The rest of the CloudFormation template follows this, and, without the lines above, the template deploys (an S3 bucket, DynamoDB table and a python 3.7-based Lambda).

The hope was that I could then just use:

!FindInMap [StandardResourcesMap,AWSExecuteApi,string]

whenever i needed the long-winded value, however the template fails validation with:

An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Every Mappings attribute must be a String or a List.

as the title says.

I have tried a number of variations on the Mappings such as using the !Ref variant:

Mappings:
  StandardResourcesMap:
    AWSExecuteApi:
      string: !Join [ ':' , ['arn', !Ref 'AWS::Partition', 'execute-api', !Ref 'AWS::Region', !Ref 'AWS::AccountId'] ]
    AWSLambdaFunctions:
      string: !Join [ ':' , ['arn', !Ref 'AWS::Partition', 'apigateway', !Ref 'AWS::Region', 'lambda:path/2015-03-31/functions/'] ]

and I just get pulled up on various validation errors, centring on the one presented above.

any help would be greatly appreciated.

Upvotes: 17

Views: 9980

Answers (1)

Jason Wadsworth
Jason Wadsworth

Reputation: 8885

The problem is this: You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section. Mappings

Upvotes: 26

Related Questions