【问题标题】:Cloudformation ipv4 and ipv6 egressCloudformation ipv4 和 ipv6 出口
【发布时间】:2021-09-24 20:50:07
【问题描述】:

我想向我的安全组添加一条 alltraffic ipv4 和 alltraffic ipv6 出站规则。但是,当我同时定义了 ipv6 时,Cloudformation 一直只构建 ipv6。

我从以下代码开始:

    SecurityGroupEgressAllTrafficipv4:
      Type: 'AWS::EC2::SecurityGroupEgress'
      Properties:
        Description: "Allow all outbound traffic by default"
        GroupId: !Ref "SecurityGroup"
        CidrIp: "0.0.0.0/0"        
        IpProtocol: "-1"

    SecurityGroupEgressAllTrafficipv6:
      Type: 'AWS::EC2::SecurityGroupEgress'
      Properties:
        Description: "Allow all outbound traffic by default"
        GroupId: !Ref "SecurityGroup"
        CidrIpv6: "::/0"        
        IpProtocol: "-1"

由于它只是构建 ipv6,我发现这篇文章作为参考:How to specify both IPv6 and v4 in Security Groups in CloudFormation?。我尝试了评论者发布的格式并收到错误:错误:模板格式错误:任何属性成员都必须是对象。

    SecurityGroupEgressAllTraffic:
      Type: 'AWS::EC2::SecurityGroupEgress'
      Properties:
        - Description: "Allow all outbound traffic by default"
          GroupId: !Ref "SecurityGroup"
          CidrIp: "0.0.0.0/0"        
          IpProtocol: "-1"
        - Description: "Allow all outbound traffic by default"
          GroupId: !Ref "SecurityGroup"
          CidrIpv6: "::/0"        
          IpProtocol: "-1"

有没有人成功地尝试过这个?谢谢。

【问题讨论】:

    标签: amazon-web-services amazon-ec2 amazon-cloudformation


    【解决方案1】:

    代替:

     GroupId: !Ref "SecurityGroup"
    

    应该是:

     GroupId: !GetAtt SecurityGroup.GroupId
    

    【讨论】:

    • 我尝试更新出口规则的 GroupId 属性并收到错误:E1012 Ref SecurityGroup.GroupId not found as a resource or parameter 我能够仅使用 GroupId 创建出口规则:!Ref "SecurityGroup ”。看来问题与参考无关。由于某种原因,我只能创建一个 alltraffic ipv* 规则。当我添加两个时,只会创建 ipv6 alltraffic 规则。
    • 此外,我定义了一个 ALLTCP 出口规则,并且正在构建良好...问题与 ALLTRAFFIC 有某种关系?
    • @TechTraffic 我建议提供完整的模板和错误。从您写的内容来看,一切都很好,您的短 sn-p 代码没有问题。
    • 我很抱歉我最初阅读的代码不正确。当我修改代码时,我使用了!Ref SecurityGroup.GroupId。我没有发现 !GetAtt 的区别。当我将其更改为 !GetAtt 时,这确实有效。谢谢。
    猜你喜欢
    • 2021-11-08
    • 2012-09-10
    • 2016-09-19
    • 2018-11-29
    • 1970-01-01
    • 2014-07-05
    • 2018-07-14
    • 1970-01-01
    • 2012-07-12
    相关资源
    最近更新 更多