使用子网时AWS Cloudformation出现错误

时间:2018-07-26 12:06:37

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

由于某些奇怪的原因,您能否检查我使用YAMLCloudformation创建的代码,我得到以下错误。对不起,代码对齐。

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)

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

1 个答案:

答案 0 :(得分:0)

当您为实例指定 SubnetId 时,您应该使用安全组 ID 而不是安全组名称。只需在 EC2 实例部分用 SecurityGroupIds 替换 SecurityGroups。

参考:

  1. reference1
  2. Reference2
  3. Reference3