的具體問題是,你不能在一個Mappings
值內使用Ref
,作爲Mappings文檔中指出:
You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section.
作爲替代方案,可以使用Conditions來完成你的模板正在嘗試。下面是一個完整的工作示例:
{
"Description": "Create an ElastiCache SubnetGroup with different subnet depending on the current AWS region."
"Conditions": {
"us-east-1": {"Fn::Equals": [{"Ref":"AWS::Region"}, "us-east-1"]},
"us-west-2": {"Fn::Equals": [{"Ref":"AWS::Region"}, "us-west-2"]}
},
"Resources": {
"VPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16"
}
},
"AppSubnetA": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {"Ref": "VPC"},
"CidrBlock": "10.0.0.0/24",
"AvailabilityZone": {"Fn::Select": [1, {"Fn::GetAZs": ""}]}
}
},
"AppSubnetB": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {"Ref": "VPC"},
"CidrBlock": "10.0.1.0/24",
"AvailabilityZone": {"Fn::Select": [1, {"Fn::GetAZs": ""}]}
}
},
"ElastiCacheSubnetGroup": {
"Type": "AWS::ElastiCache::SubnetGroup",
"Properties": {
"Description": "SubnetGroup",
"SubnetIds": {"Fn::If": ["us-east-1", [
{"Ref": "AppSubnetA"}
],
{"Fn::If": ["us-west-2",
[
{"Ref": "AppSubnetB"}
],
{"Ref":"AWS::NoValue"}
]}
]}
}
}
}
}
哦,真的? 'AppSubnets'引用是一個Refs數組,是否不滿足這個數組的需要? –
一個合理的人可能會這樣想,但它會給你一個抱怨數據類型的錯誤信息:)。 – James
我已嘗試,以及,提供以下對SubnetIds但它產生了同樣的錯誤: 「SubnetIds」:[{ 「FN :: FindInMap」:[ 「RegionMap」, { 「參考」:」 AWS :: Region「 }, 」AppSubnets「 ] }] –