amazon-web-services - 如何避免cloudformation与安全组的循环引用?

标签 amazon-web-services aws-cloudformation

如何避免 cloudformation 模板之间的循环引用?

例如我的 Web 服务器有一个模板,数据库实例有另一个模板。模板数据库将类似于:

"Database": {
  "Type":"AWS::RDS::DBInstance",
  "Properties": {
     // lots of other props
     "VPCSecurityGroups": [ {"Ref":"DBSecurityGroup"} ]
  }
},
"DBSecurityGroup" : {
  "Type":"AWS::RDS::DBSecurityGroup",
  "Properties": {
    // lots of other props
    "SecurityGroupIngress": [{... "SourceSecurityGroupId":{"Ref":"WebSecurityGroup"}}]
  }
}

但是在我的 Web 服务器模板中,我需要引用 DBSecurityGroup:

"WebServer": {
  "Type":"AWS::EC2::Instance",
  "Properties": {
     // lots of other props
     "SecurityGroups": [ {"Ref":"DBSecurityGroup"} ]
  }
},
"WebSecurityGroup" : {
  "Type":"AWS::EC2::SecurityGroup",
  "Properties": {
    // lots of other props
    "SecurityGroupEgress": [{... "SourceSecurityGroupId":{"Ref":"DBSecurityGroup"}}]
  }
}

如何避免模板之间的这些循环引用?

最佳答案

使用单独的 AWS::EC2::SecurityGroupEgress 资源,而不是 SecurityGroupEgress 属性。

查看示例片段 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/quickref-ec2.html#scenario-ec2-security-group-ingress

关于amazon-web-services - 如何避免cloudformation与安全组的循环引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24853034/

相关文章:

amazon-web-services - AWS CloudFormation - 有什么方法可以使用内部函数作为对象键?

amazon-web-services - 无服务器框架和 CloudFormation 之间的区别?

amazon-web-services - SAM/无服务器/CodeBuild 说明

amazon-web-services - 可以使用默认值向 Amazon SimpleDB 域添加新列吗?

amazon-web-services - 参数部分中的跨堆栈引用

python - 使用 headless 浏览器呈现 100,000 个页面,aws 上每秒每个 cpu 的最大值

amazon-web-services - 将 ApplicationListenerRule 添加到现有的 ApplicationListener 会出现错误 'A listener already exists on this port for this load balancer'

aws-cloudformation - 更新 Cloud Formation 配置文件中的 EmailSubject 和 EmailMessage

amazon-web-services - 如何通过 CLI 加密 Lambda 的环境变量?

amazon-web-services - Cloudformation AWS CLI 查询具有多个嵌套堆栈的所有堆栈资源