如何指定安全组中的所有端口 - CloudFormation

How to specify all ports in Security group - CloudFormation

我现在有这样的 CloudFormation 脚本:

    "SecurityGroupIngress" : [{
      "IpProtocol" : "tcp",
      "FromPort" : "0",
      "ToPort" : "65535",
      "CidrIp" : "0.0.0.0/0"
    }]

看起来像这样,很好:

但我想知道如何更新模板以获取此内容:

注意端口显示全部。我也想知道他们有什么不同吗?

我发布的原始解决方案(并被原始发布者接受)停止工作,因为 AWS 不再支持它。为了避免大量的反对票,我删除了答案。备选方案是:

  • 指定端口 0 和 65535

所有 协议打开所有端口,而不仅仅是 TCP(如下文 thewire247 所建议)

"SecurityGroupIngress" : [{
  "IpProtocol" : "-1",
  "CidrIp" : "0.0.0.0/0"
}]

如果您希望允许所有协议和所有端口,则可以执行以下操作

{
  "IpProtocol" : "-1"
  "CidrIp" : "0.0.0.0/0"
}

FromPort
TCP 和 UDP 协议的端口范围的开始,或 ICMP 类型号。如果为 IpProtocol 属性 指定 icmp,则可以将 -1 指定为通配符(即任何 ICMP 类型编号)。

ToPort
TCP 和 UDP 协议或 ICMP 代码的端口范围结束。如果为 IpProtocol 属性 指定 icmp,则可以将 -1 指定为通配符(即任何 ICMP 代码)。

例如
{ "IpProtocol" : "icmp", "FromPort" : "8", "ToPort" : "-1", "CidrIp" : "10.0.0.0/24" }

参考:
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-ingress.html