AWS CloudFromation使用现有安全组

时间:2016-01-13 11:31:32

标签: amazon-web-services amazon-cloudformation

我想在cloudformation模板上使用现有的安全组。 现在我有模板创建2 SG,

 "InstanceMember1": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "SubnetId": {
          "Ref": "privateSubnetA"
        },
        "SecurityGroupIds": [
          {
            "Ref": "MongoSg"
          },
          {
            "Ref": "mongoTrafficSG"
          } 
        ],
    }
}

"MongoSg": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "GroupDescription": "MongoDB security group",
        "SecurityGroupIngress": [
          {
            "IpProtocol": "tcp",
            "FromPort": "22",
            "ToPort": "22",
            "SourceSecurityGroupId": {
              "Ref": "bastionSG"
            }
          }
        ],
        "VpcId": "%%vpc-id%%",
      }
}
}

现在我想添加实例存在的安全组ID,有什么建议吗?

1 个答案:

答案 0 :(得分:10)

您可以继续并指定安全组名称: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-instance.html#cfn-ec2-instance-securitygroups

 "InstanceMember1": {
      "Type": "AWS::EC2::Instance",
      "Properties": {
        "SubnetId": {
          "Ref": "privateSubnetA"
        },
        "SecurityGroups": [ "mysuperawesomealreadyexistinggroup"],
    }
}