在下面的代码中,我试图引用我为创建EC2实例的子网\ cidr块而创建的参数。
我猜是因为我创建了CFCidrVPC1作为字符串,而实际的IP地址不是字符串。
我在这里不见了。
有人可以在这里引导我。我尝试这样做的原因是将来重复使用代码。我还尝试在Ref
函数中使用Fn::Cidr
函数,但这也不起作用。因此,将其替换为cidr块。
我得到的错误是"Value of property SubnetId must be of type String"
。
请找到我的完整脚本:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creating template to deploy 3 ec2 instances in 3 different AZs",
"Parameters": {
"CFCidrVPC1": {
"Type": "String",
"Default": "10.10.0.0/16"
},
"CFCidrVPC2": {
"Type": "String",
"Default": "10.20.0.0/16"
},
"CFEC2Instancetype": {
"Type": "String",
"Default": "t2.micro",
"Description": " Only t2.micro is available in the free tier account hence no any other options"
}
},
"Resources": {
"VPC1": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref": "CFCidrVPC1"
},
"EnableDnsHostnames": "False",
"EnableDnsSupport": "False",
"InstanceTenancy": "default"
}
},
"VPC2": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": {
"Ref": "CFCidrVPC2"
},
"EnableDnsHostnames": "False",
"EnableDnsSupport": "False",
"InstanceTenancy": "default"
}
},
"CFsubnet1": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"0",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC1"
}
}
},
"CFsubnet2": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"1",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC1"
}
}
},
"CFsubnet3": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"0",
{
"Fn::Cidr": [
"10.20.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC2"
}
}
},
"CFsubnet4": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"CidrBlock": {
"Fn::Select": [
"1",
{
"Fn::Cidr": [
"10.10.0.0/16",
"2",
"8"
]
}
]
},
"VpcId": {
"Ref": "CFCidrVPC2"
}
}
},
"FirstECSinVPC1AZ1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet1"
}
}
},
"FirstECSinVPC1AZ2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"1",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet2"
}
}
},
"FirstECSinVPC2AZ1": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"0",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet3"
}
}
},
"FirstECSinVPC2AZ2": {
"Type": "AWS::EC2::Instance",
"Properties": {
"AvailabilityZone": {
"Fn::Select": [
"1",
{
"Fn::GetAZs": ""
}
]
},
"ImageId": "ami-005bdb005fb00e791",
"InstanceType": {
"Ref": "CFEC2Instancetype"
},
"SubnetId": {
"ref": "CFsubnet4"
}
}
}
}
}
答案 0 :(得分:1)
所有云信息都区分大小写。
您有:
"SubnetId": {
"ref": "CFsubnet2"
}
尝试:
"SubnetId": {
"Ref": "CFsubnet2"
}
所有情况。