Разрешить каждому экземпляру в одной группе безопасности обмениваться данными друг с другом в Cloud Formation JSON?

Я создаю JSON Cloud Formation для определения экземпляров EC2 и групп безопасности.

Мне нужно создать группу безопасности, которая позволяет каждому принадлежащему ей экземпляру обмениваться любыми данными друг с другом.

Мой JSON был таким:

"InternalSecurityGroup" : {
  "Type" : "AWS::EC2::SecurityGroup",
  "Properties" : {
    "VpcId" : {"Ref" : "myVPC"},
    "GroupDescription" : "Allow the machines in this group to share all kinds of traffic between each other",
    "SecurityGroupIngress" : [
      {
        "IpProtocol" : "-1",
        "FromPort": "-1",
        "ToPort": "-1",
        "SourceSecurityGroupId" : { "Ref" : "InternalSecurityGroup" }
      }
    ],
    "SecurityGroupEgress" : [
      {
        "IpProtocol" : "-1",
        "FromPort": "-1",
        "ToPort": "-1",
        "DestinationSecurityGroupId" : { "Ref" : "InternalSecurityGroup" }
      }
    ]

  }
},

Но это показывает мне следующую ошибку:

Ошибка клиента (ValidationError) при вызове операции CreateStack: Циклическая зависимость между ресурсами

Чтобы исправить это, я изменил свой код на CidrIp вместо SourceSecurityGroupId, определяя подсеть, в которой находятся экземпляры.

Можно ли ссылаться на одну и ту же группу безопасности? Каков наилучший (или правильный) способ добиться того, чего я хочу?


person lrepolho    schedule 06.11.2014    source источник


Ответы (2)


Как указано в документации вы можете использовать AWS::EC2::SecurityGroupEgress и AWS::EC2::SecurityGroupIngress ресурсы для определения самоссылающихся правил группы безопасности:

Важно

Если вы хотите создать перекрестные ссылки на две группы безопасности в правилах входа и выхода этих групп безопасности, используйте ресурсы AWS::EC2::SecurityGroupEgress и AWS::EC2::SecurityGroupIngress для определения ваших правил. Не используйте встроенные правила входа и выхода в файле AWS::EC2::SecurityGroup. Если вы это сделаете, это вызовет циклическую зависимость, которую AWS CloudFormation не допускает.

Результат выглядит следующим образом:

Запустить стек

{
   "Resources":{
      "myVPC":{
         "Type":"AWS::EC2::VPC",
         "Properties":{
            "CidrBlock":"10.0.0.0/16"
         }
      },
      "InternalSecurityGroup":{
         "Type":"AWS::EC2::SecurityGroup",
         "Properties":{
            "VpcId":{
               "Ref":"myVPC"
            },
            "GroupDescription":"Allow the machines in this group to share all kinds of traffic between each other"
         }
      },
      "InternalSecurityGroupIngress":{
         "Type":"AWS::EC2::SecurityGroupIngress",
         "Properties":{
            "IpProtocol":"-1",
            "FromPort":"-1",
            "ToPort":"-1",
            "SourceSecurityGroupId":{
               "Ref":"InternalSecurityGroup"
            },
            "GroupId":{
               "Ref":"InternalSecurityGroup"
            }
         }
      },
      "InternalSecurityGroupEgress":{
         "Type":"AWS::EC2::SecurityGroupEgress",
         "Properties":{
            "IpProtocol":"-1",
            "FromPort":"-1",
            "ToPort":"-1",
            "DestinationSecurityGroupId":{
               "Ref":"InternalSecurityGroup"
            },
            "GroupId":{
               "Ref":"InternalSecurityGroup"
            }
         }
      }
   }
}
person wjordan    schedule 04.01.2017

Определите две группы безопасности, это должно работать немного лучше:

 "InternalSecurityGroup1" : {
  "Type" : "AWS::EC2::SecurityGroup",
  "Properties" : {
    "VpcId" : {"Ref" : "myVPC"},
    "GroupDescription" : "Allow the machines in this group to share all kinds of traffic between each other",
    "SecurityGroupIngress" : [ {
        "IpProtocol" : "-1",
        "FromPort": "-1",
        "ToPort": "-1",
        "SourceSecurityGroupId" : { "Ref" : "InternalSecurityGroup2" }
      }
    ]
  }
}


"InternalSecurityGroup2" : {
  "Type" : "AWS::EC2::SecurityGroup",
  "Properties" : {
    "VpcId" : {"Ref" : "myVPC"},
    "GroupDescription" : "Allow the machines in this group to share all kinds of traffic between each other",
    "SecurityGroupIngress" : [ {
        "IpProtocol" : "-1",
        "FromPort": "-1",
        "ToPort": "-1",
        "SourceSecurityGroupId" : { "Ref" : "InternalSecurityGroup1" }
      }
    ]
  }
}
person Bryan Kroger krogebry    schedule 09.11.2014