Amazon web services 使用子网时发生错误

Amazon web services 使用子网时发生错误,amazon-web-services,yaml,amazon-cloudformation,Amazon Web Services,Yaml,Amazon Cloudformation,请检查我使用YAML创建的Cloudformation代码,因为一些奇怪的原因,我得到了以下错误。对不起,代码对齐了 Error: CREATE_FAILED AWS::EC2::Instance Ec2InstanceOne The parameter groupName cannot be used with the parameter subnet (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParamete

请检查我使用
YAML
创建的
Cloudformation
代码,因为一些奇怪的原因,我得到了以下错误。对不起,代码对齐了

Error: CREATE_FAILED    AWS::EC2::Instance  Ec2InstanceOne  The parameter groupName cannot be used with the parameter subnet (Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterCombination; Request ID: a4018f68-7454-4f1f-ba81-6ec3b3c78d98)


为实例指定子网ID时,应使用安全组ID而不是安全组名称。只需在EC2实例部分用SecurityGroupId替换SecurityGroups

参考:


  • 您是否尝试使用“安全组ID”而不是“安全组”?正如在《感谢大卫·德温》中所说的那样,它现在起作用了,这显然是我的错误。
    Resources:
    Ec2InstanceOne:
    Type: AWS::EC2::Instance
      Properties:
      AvailabilityZone: eu-west-1a
      ImageId: ami-466768ac
      InstanceInitiatedShutdownBehavior: terminate #stop or Terminate
      InstanceType: t2.micro
      KeyName: Resources # If we are mentioning in Parameters we have to mention 
      AWS::EC2::KeyPair::KeyName
    
    
      SecurityGroups:
        - !Ref Ec2SecurityGroup
      SubnetId: !Ref MySubnet
    
    Ec2SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: This is to allow HTTP site access
      VpcId: !Ref MyVpc
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 0.0.0.0/0
    
    MyVpc:
    Type: "AWS::EC2::VPC"
    Properties:
    CidrBlock: 192.168.0.0/16
    
    MyRoute:
    Type: AWS::EC2::Route
    Properties:
    RouteTableId: 10.120.0.0/16
    DestinationCidrBlock: 0.0.0.0/0
    InstanceId: !Ref Ec2InstanceOne
    
    MySubnet:
    Type: AWS::EC2::Subnet
    Properties:
    AvailabilityZone: eu-west-1a
    CidrBlock: 192.168.1.0/24
    VpcId: !Ref MyVpc