CloudFormation — possible to have nested Mappings?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 08:31:32

Something like this:

"ImageMap" : {
    "us-east-1" : { "dev" : "ami-11111111", "qa" : "ami-22222222" },
    "us-west-1" : { "dev" : "ami-33333333", "qa" : "ami-44444444" }
 }

and then to access these values:

"Value" : {
    "Fn::FindInMap" : [
        "ImageMap", { "Ref" : "AWS::Region" }, { "Ref" : "EnvironmentType" }
    ]
}

I ended up doing it like this:

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

The important point here is that the objects alternate between "mappings" and keys". So in this situation, "dev" is a Mapping, "us-east-1" is a key, "ImageId" is a mapping, and "something" is a key. Mapping names cannot have non-alphanumeric characters, so Region names cannot be Mappings. Thus, using the environment as the first parameter and using the region name as the second parameter is mandatory.

It seems to me like the Mappings section of CloudFormation has a lot of really strange arbitrary rules, and it surprises me that it isn't more flexible, but there you have it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!