代码之家  ›  专栏  ›  技术社区  ›  Johnathon Sullinger

不为Cloud标记中的键赋值

  •  0
  • Johnathon Sullinger  · 技术社区  · 7 年前

    我有以下云形成模板来创建专有网络。VPC名称是根据创建模板的区域和环境生成的。VPC创建时没有任何问题,并且正在运行 aws cloud formation validate-template --template-url https://foo.template 不抱怨任何语法。

    我希望VPC的名称为:

    vpc-uw1-d-fs

    取而代之的是专有网络留下了一个空名称,而名称标签有一个空值。我没有正确使用该功能吗?如果我移除 Fn::FindInMap 函数用法,我得到生成的名称-它只是缺少环境映射值。

    {
        "AWSTemplateFormatVersion": "2010-09-09",
        "Description": "VPC for a new environment to use.",
        "Parameters": {
            "EnvironmentName": {
                "Description": "Name of the environment that this VPC will be used for.",
                "Type": "String",
                "MinLength": "2",
                "MaxLength": "20",
                "AllowedPattern": "[a-zA-Z]*",
                "AllowedValues": [
                    "Development",
                    "QA",
                    "Test",
                    "Production"
                ]
            }
        },
        "Resources": {
            "VPC": {
                "Type": "AWS::EC2::VPC",
                "Properties": {
                    "CidrBlock": "10.0.0.0/16",
                    "EnableDnsSupport": false,
                    "EnableDnsHostnames": false,
                    "InstanceTenancy": "default",
                    "Tags": [ { 
                        "Key": "Name",
                        "Value": {
                            "Fn::Join": [
                                "-",
                                [
                                    "vpc",
                                    { "Ref": "AWS::Region" },
                                    { "Fn::FindInMap": [
                                        "EnvironmentMap", { "Ref": "EnvironmentName" }, "AbbreviatedName"
                                    ]},
                                    "fs"
                                ]
                            ]
                        }
                    }]
                }
            }
        },
        "Mappings": {
            "RegionMap": {
                "us-east-1": {
                    "regionName": "ue1"
                },
                "us-west-1": {
                    "regionName": "uw1"
                }
            },
            "EnvironmentMap": {
                "Development": { 
                    "AbbreviatedName": "d"
                },
                "QA": { 
                    "AbbreviatedName": "qa"
                },
                "Test": { 
                    "AbbreviatedName": "t"
                },
                "Production": { 
                    "AbbreviatedName": "p"
                }
            }
        },
        "Outputs": {
    
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   John Rotenstein    7 年前

    你的模板对我来说非常好。

    我在实验室里查过了 ap-southeast-2 区域并生成标签:

    • 姓名: vpc-ap-southeast-2-d-fs

    (小标题) RegionMap 未在给定的模板中使用。)