我正在尝试编写一个云形成模板,为负载均衡器设置安全组。我可以通过以下方式为安全组选择 VPC:
"Parameters" : {
"VpcId" : {
"Description" : "VPC associated with the provided subnets",
"Type" : "List<AWS::EC2::VPC::Id>"
},
},
然后创建负载均衡器安全组:
"LbSecurityGroup" : {
"Type" : "AWS::EC2::SecurityGroup",
"Properties" : {
"GroupDescription" : "Stack LBs",
"VpcId" : { "Ref" : "VpcId" }
}
},
当我启动堆栈时,它失败了:
CREATE_FAILED AWS::EC2::SecurityGroup LbSecurityGroup
Value of property VpcId must be of type String
首先,为什么 AWS::EC2::SecurityGroup.VpcId 不是 AWS::EC2::VPC::Id 类型?其次,我如何将其按摩成一根绳子?
提前致谢!
最佳答案
额外的、更具体的类型(例如 AWS::EC2::SecurityGroup
而不仅仅是 String
)是新的,并且仅用于参数 - 目的是在尝试创建堆栈之前验证资源是否存在。请参阅Using the New CloudFormation Parameter Types了解更多信息。
在您的情况下,我认为问题在于 VpcId
参数的类型是 AWS::EC2::SecurityGroup
值的列表,而不是单个值AWS::EC2::SecurityGroup
值? AWS::EC2::SecurityGroup
资源的 VpcId
属性仅采用单个字符串,而不是字符串列表 - 请参阅 VpcId .
关于amazon-web-services - Cloudformation AWS::EC2::Security Group Vpc Id 需要一个字符串吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29810122/