如何在 AWS Cloudformation 的 "outputs" 中获取子网的 "cidrblock"?
How get "cidrblock" of a subnet in the "outputs" of a AWS Cloudformation?
我正在编写 AWS Code 格式。我必须打印子网的 Cidrblock。但这是行不通的。请帮助
"Resources": {
"Subnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.0.0/16",
}
},
Outputs : {
"SubnetCIDR": {
"Value": {
"Fn::GetAtt": [
"Subnet",
"CidrBlock"
]
},
"Description": "The CIDR"
},
}
这不起作用。上传模板时显示以下错误消息:
Template validation error: Template error: resource Subnet does not
support attribute type CidrBlock in Fn::GetAtt
不支持。
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
如果您查看文档,唯一支持的属性是 AvailabilityZone
由于您似乎对 CIDR 块进行了硬编码,因此您可以将其设置为参数,然后在两个地方都引用该参数。
"Parameters" : {
"CidrBlock" : {
"Type" : "String",
"Default" : "10.0.0.0/16"
}
},
"Resources" : {
"Subnet" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"VpcId" : {
"Ref" : "VPC"
},
"CidrBlock" : { "Ref" : "CidrBlock" }
}
}
},
"Outputs" : {
"SubnetCIDR" : {
"Value" : { "Ref" : "CidrBlock" },
"Description": "The CIDR"
}
}
我正在编写 AWS Code 格式。我必须打印子网的 Cidrblock。但这是行不通的。请帮助
"Resources": {
"Subnet": {
"Type": "AWS::EC2::Subnet",
"Properties": {
"VpcId": {
"Ref": "VPC"
},
"CidrBlock": "10.0.0.0/16",
}
},
Outputs : {
"SubnetCIDR": {
"Value": {
"Fn::GetAtt": [
"Subnet",
"CidrBlock"
]
},
"Description": "The CIDR"
},
}
这不起作用。上传模板时显示以下错误消息:
Template validation error: Template error: resource Subnet does not support attribute type CidrBlock in Fn::GetAtt
不支持。
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-subnet.html
如果您查看文档,唯一支持的属性是 AvailabilityZone
由于您似乎对 CIDR 块进行了硬编码,因此您可以将其设置为参数,然后在两个地方都引用该参数。
"Parameters" : {
"CidrBlock" : {
"Type" : "String",
"Default" : "10.0.0.0/16"
}
},
"Resources" : {
"Subnet" : {
"Type" : "AWS::EC2::Subnet",
"Properties" : {
"VpcId" : {
"Ref" : "VPC"
},
"CidrBlock" : { "Ref" : "CidrBlock" }
}
}
},
"Outputs" : {
"SubnetCIDR" : {
"Value" : { "Ref" : "CidrBlock" },
"Description": "The CIDR"
}
}