Serverless mappings: not sure why it is not working

I’m trying to use a “mappings” section in the serverless.yml file and I’m getting an error that I can’t quite understand.

Here is how I’m trying to use it (i left some resources out to isolate the issue):

resources:
  Mappings:
    S3HostedZoneIds:
      us-west-2: Z3BJ6K6RIION7M
      ca-central-1: Z1QDHH18159H29
  Resources:
    DnsRecord:
      # See this for more details on how to create DNS Record for a bucket:
      # https://www.serverlessops.io/blog/static-websites-on-aws-s3-with-serverless-framework
      Type: "AWS::Route53::RecordSet"
      Properties:
        AliasTarget:
          DNSName: s3-website-#{AWS::Region}.amazonaws.com
          # https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
          HostedZoneId: Fn::FindInMap
                    - S3HostedZoneIds
                    - Ref "#{AWS::Region}"
        HostedZoneId: ${ssm:/${self:provider.stage}/route53/clearcareonline_zone_id}
        Name:
          Ref: SafeModeStaticSite
        Type: 'A'

I get this error:

The CloudFormation template is invalid: Template format error: Every Mappings member us-west-2 must be a map

I think I’m doing a newbie error when using “mappings”, but I can’t quite figure it out.

Hi, it seems to me that you need to add a name for each value.
Here is an example

  Mappings:
    S3HostedZoneIds:
      us-west-2: 
            zoneId: Z3BJ6K6RIION7M
      ca-central-1: 
            zoneId: Z1QDHH18159H29

now you can get a value

...
  HostedZoneId: !FindInMap [S3HostedZoneIds, !Ref "AWS::Region", zoneId]
...

Hope it will help :slight_smile:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html

1 Like

Yes! Thank you @moro !!! That did the trick!

np, happy to help :slight_smile: