【问题标题】:Can I use public security groups in cloud formation for ec2 launch configs?我可以在云形成中使用公共安全组来进行 ec2 启动配置吗?
【发布时间】:2015-01-02 07:15:03
【问题描述】:

我可以在云形成中使用公共安全组来进行 ec2 启动配置吗? 我试图简单地指示 cloudformation 堆栈使用现有的集合,但它无法创建这些资源。 我尝试将这些安全组创建为每个堆栈的滚动集(ssh1、ssh2...),但也没有这样的运气。

如果您的答案包含一个关于如何准确执行此操作的代码 sn-p,那将是非常酷的。谢谢。

【问题讨论】:

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


    【解决方案1】:

    您可以参考示例模板进行深入了解。

    Amazon EC2 instance in a security group

    这是你感兴趣的部分。

      "Resources" : {
        "EC2Instance" : {
          "Type" : "AWS::EC2::Instance",
          "Properties" : {
            "InstanceType" : { "Ref" : "InstanceType" },
            "SecurityGroups" : [ { "Ref" : "InstanceSecurityGroup" } ],    # <--Here is the refer
            "KeyName" : { "Ref" : "KeyName" },
            "ImageId" : { "Fn::FindInMap" : [ "AWSRegionArch2AMI", { "Ref" : "AWS::Region" },
                              { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }
          }
        },
    
        "InstanceSecurityGroup" : {
          "Type" : "AWS::EC2::SecurityGroup",
          "Properties" : {
            "GroupDescription" : "Enable SSH access via port 22",
            "SecurityGroupIngress" : [ {
              "IpProtocol" : "tcp",
              "FromPort" : "22",
              "ToPort" : "22",
              "CidrIp" : { "Ref" : "SSHLocation"}
            } ]
          }
        }
      },
    

    以上示例创建一个新的安全组,并将其分配给一个新的 ec2 实例。如果你已经存在安全组,那么你不需要InstanceSecurityGroup部分,并将真实的安全组名称分配给ec2实例:

    "SecurityGroups" : "REAL Security Group Name",
    

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 2021-03-02
      • 1970-01-01
      • 2018-07-05
      • 2023-04-04
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多