【问题标题】:AWS CloudFormation: SecurityGroup refers to another security groupAWS CloudFormation:SecurityGroup 指的是另一个安全组
【发布时间】:2018-12-26 21:10:41
【问题描述】:

当该部分已满时,此代码会引发“组描述为空”。

Resources:
  FormulationSG:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      Tags:
        - Key: 'Name'
          Value: 'FormulationSG'
      VpcId: 'vpc-yyy00yyy'
      GroupDescription: 'Port Rules for Formulation and on Port 11.'
      SecurityGroupIngress:
        - IpProtocol: tcp
          CidrIp: 192.168.0.0/8
          FromPort: '11'
          ToPort: '11'
        - IpProtocol: tcp
          FromPort: '91'
          ToPort: '91'
          SourceSecurityGroupName: 'sg-1234567'

忽略所有已更改的数字,但我遇到的问题是,一旦我尝试获取现有的安全组“sg-1234567”,它就会给我一条错误消息,指出组描述已经在引号中时无效。

【问题讨论】:

  • 这是 VPC 安全组还是非 VPC?对于 VPC 中的实例,您必须指定 SourceSecurityGroupId。参考docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/…
  • sg-1234567 是安全组 ID,而不是名称。
  • 注意 - 我必须删除第二个“安全组入口”块。
  • @Dasman 您可能应该删除操作中的编辑,并显示您需要删除的行。看到您评论需要删除第二个 SGI 块,这有点令人困惑,但它不存在。也许发布更正的版本作为答案。

标签: amazon-web-services yaml amazon-cloudformation aws-security-group


【解决方案1】:

您正在使用SourceSecurityGroupName 属性,但您没有传递Name...您正在传递ID。因此尝试使用SourceSecurityGroupId 而不是SourceSecurityGroupName ;-)

【讨论】:

  • 谢谢!当我如此接近时,这总是让我恼火。
【解决方案2】:

SourceSecurityGroupName 仅适用于 EC2 经典版。您正在使用 VPC EC2(推荐)。请改用SourceSecurityGroupId。您不需要使用引号。这个例子可以正常工作:

Resources:
  FormulationSG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      Tags:
        - Key: Name
          Value: FormulationSG
      VpcId: vpc-yyy00yyy
      GroupDescription: Port Rules for Formulation and on Port 11.
      SecurityGroupIngress:
        - IpProtocol: tcp
          CidrIp: 192.168.0.0/8
          FromPort: 11
          ToPort: 11
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 91
          ToPort: 91
          SourceSecurityGroupId: sg-1234567

【讨论】:

  • 谢谢!尤其是逗号部分!
  • 另外,您可以参考以下其他 SG:SourceSecurityGroupId: !GetAtt OtherSecurityGroup.GroupId 安全组 ID 不是硬编码
猜你喜欢
  • 2018-01-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-13
  • 1970-01-01
  • 1970-01-01
  • 2021-08-16
  • 2019-03-26
相关资源
最近更新 更多