Amazon web services 云形成安全组未创建入口规则

Amazon web services 云形成安全组未创建入口规则,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,我为一个安全组创建了一个cloudformation模板,其中包含3个入口规则,一个用于SSH,一个用于HTTP,另一个用于HTTP(port8080) 首先,当我包含SourceSecurityGroupOwnerId时,组根本不会创建。当我删除此项时,组将创建一个规则(ssh规则),但仅使用一个规则 以下是完整的模板: AWSTemplateFormatVersion: 2010-09-09 Description: Provision security group to allow SSH

我为一个安全组创建了一个cloudformation模板,其中包含3个入口规则,一个用于SSH,一个用于HTTP,另一个用于HTTP(port8080)

首先,当我包含SourceSecurityGroupOwnerId时,组根本不会创建。当我删除此项时,组将创建一个规则(ssh规则),但仅使用一个规则

以下是完整的模板:

AWSTemplateFormatVersion: 2010-09-09
Description: Provision security group to allow SSH access to instance
Parameters:
  EnvironmentName:
    Description: An environment name that will be prefixed to resource names
    Type: String
  SSHLocation:
    Description: The IP address range that can be used to SSH to the EC2 instances
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.

Resources:
  InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      VpcId: !ImportValue hvfVPC-Name
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName
      GroupDescription: Enable SSH access and HTTP from the load balancer only
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '22'
          ToPort: '22'
          CidrIp: !Ref SSHLocation
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          SourceSecurityGroupOwnerId: !ImportValue wordpressELB-SG-Id
          SourceSecurityGroupName: !ImportValue wordpressELB-SG-Name
        - IpProtocol: tcp
          FromPort: '8080'
          ToPort: '8080'
          SourceSecurityGroupOwnerId: !ImportValue wordpressELB-SG-Id
          SourceSecurityGroupName: !ImportValue wordpressELB-SG-Name
这最终只是运行了很长一段时间而没有实际创建组。当我同时删除SourceSecurityGroupId和SourceSecurityGroupName时,模板将运行,但它只创建一个入口规则

我已经三次检查以确保导出是正确的,它们是正确的,但是由于某种原因,除非我删除这两行,否则Cloudformation将挂起

附上图片以供澄清


我的猜测是,您应该简单地指定
SourceSecurityGroupId
,而不是
SourceSecurityGroupOwnerId
SourceSecurityGroupName
。大致如下:

    - IpProtocol: tcp
      FromPort: 80
      ToPort: 80
      SourceSecurityGroupId: !ImportValue wordpressELB-SG-Id
类似的配置很适合我

有关的文件说:

不能将此参数与以下参数结合使用:CIDR IP地址范围、IP协议、端口范围的开始和端口范围的结束

这可能是未创建规则的原因


接下来,您似乎在
SourceSecurityGroupOwnerId
中指定源安全组的ID
wordpresselbsgid
SourceSecurityGroupOwnerId
实际上是源安全组的AWS帐户ID,因此无论如何这是不正确的。

WordPress ELB安全组位于此堆栈的不同AWS帐户中?为什么指定
SourceSecurityGroupOwnerId
?不,ELB位于同一帐户上,根据文档,我发布了一张从它导出的图片。使用非默认VPR时,您必须指定ID。您是说我不能根据上述规则指定源组ID和CIDR吗?这确实有点道理,让我试一下,然后我会回来把这个标记为答案works@jhax不,我不是这么说的。您可以指定
SourceSecurityGroupId
以及CIDR等。我引用的AWS文档说,您不能结合CIDR IP地址范围、IP协议、端口范围的开始和端口范围的结束来指定
SourceSecurityGroupOwnerId
SourceSecurityGroupId
SourceSecurityGroupOwnerId
是不同的东西。