我有以下Cloud Formation模板来创建VPC。 VPC名称是基于创建模板的区域和环境生成的.VPC创建没有任何问题,并且运行aws cloud formation validate-template --template-url https://foo.template
不会抱怨任何语法。
我希望将VPC命名为:
VPC-UW1-d-FS
相反,VPC保留一个空名称,而Name标签的值为空。我没有正确使用该功能吗?如果我删除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": {
}
}
答案 0 :(得分:0)
您的模板对我来说非常合适。
我在ap-southeast-2
区域运行它并生成标记:
vpc-ap-southeast-2-d-fs
(RegionMap
未在给定的模板中使用。)