CloudFormation -- possible to have nested Mappings?

Viewed 11731

Is it possible to have nested Mappings in CloudFormation, like the following example?

"Mappings" :  
{
    "Regions" : 
    {
        "us-east-1" : 
        {
            "Environments" :
            {
                "dev" : 
                {
                    "ImageId" : "something",
                    "Subnet" : "something"
                },
                "qa" :
                {
                    "ImageId" : "something",
                    "Subnet" : "something"
                }
            }
        },
        "us-west-2" : 
        {
            "Environments" :
            {
                "dev" : 
                {
                    "ImageId" : "something",
                    "Subnet" : "something"
                },
                "qa" :
                {
                    "ImageId" : "something",
                    "Subnet" : "something"
                }
            }
        }
    }
}

When I attempt to do something like this, I get the following error:

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

If nested Mappings aren't possible, then what is the best way to store values in a CFT that require two parameters to select (such as values that depend on BOTH Region and environment)?

3 Answers

Faced the same issue. Found the following in the Fn::FindInMap documentation

The intrinsic function Fn::FindInMap returns the value corresponding to keys in a two-level map that is declared in the Mappings section.

So basically:

The following will work:

Mappings:
    map_name:
        level_1_key:
            level_2_key:
                "value"

But 3 levels won't.

Mappings:
    map_name:
        level_1_key:
            level_2_key:
                level_3_key:
                    "value"
Related