【问题标题】:I have a problem with multiple Security Groups in CloudFormationCloudFormation 中的多个安全组有问题
【发布时间】:2020-02-10 07:10:51
【问题描述】:

我正在尝试选择两个安全组,一个来自参数,另一个是新的。

但得到以下错误。我该如何解决这个问题?

AWSTemplateFormatVersion : 2010-09-09
Description: "simple web layer"
Parameters:
  ImageId:
    Description: 'web Layer'
    Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    AllowedPattern: "^[a-zA-Z][-a-zA-Z0-9]*$"
    Default: ami-244333
  Vpc:
    Description: enter vpc
    Type: List<AWS::EC2::VPC::Id>  
  Securitycab:
    Type: String
    Default: 0.0.0.0/0
    Description: enter vpc ip range    
  Subnets:
    Description: enter subnet
    Type: List<AWS::EC2::Subnet::Id>
    Default: subnet-384736383838
  Securitygroup:
    Description: enter sc
    Type: List<AWS::EC2::SecurityGroup::Id>
    Default: sg-237377383773873
Resources:
  Lpsecurity:
    Type: AWS::EC2::SecurityGroup
    Properties:
          VpcId: vpc-1a2b3c4d
          GroupDescription: Sample target security group
          SecurityGroupIngress:        
          - IpProtocol: tcp
            FromPort: 80
            ToPort: 80
            CidrIp: !Ref Securitycab
  MyEC2Instance1:
    Type: 'AWS::EC2::Instance'
    Properties:
      ImageId: !Ref ImageId
      InstanceType: t2.large
      VpcId: !Ref Vpc
      SubnetId: !Select [ 0, !Ref Subnets ]
      SecurityGroupIds:
          - !Ref Securitygroup
            !Ref Lpsecurity

错误:模板资源块中未解决的资源依赖 [Securitygroup !Ref Lpsecurity]。

【问题讨论】:

  • 我认为您在Lpsecurity 属性部分的空格过多。

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


【解决方案1】:

列表应该有每个元素之前的破折号

这是来自您的另一个I have a problem in cloud formation. Error when using Fn::Join with a parameter 问题的建议代码:

      SecurityGroupIds:
        - !GetAtt Securitygroup.GroupId
        - !GetAtt Lpsecurity.GroupId

或者,您可以使用:

      SecurityGroupIds:
          - !Ref Securitygroup
          - !Ref Lpsecurity

【讨论】:

    猜你喜欢
    • 2016-05-12
    • 1970-01-01
    • 2017-08-15
    • 2021-04-18
    • 1970-01-01
    • 2016-04-18
    • 2016-10-31
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多