【问题标题】:Get "Encountered unsupported property KeyName" error when start a stack to launch a ec2 instance启动堆栈以启动 ec2 实例时出现“遇到不支持的属性 KeyName”错误
【发布时间】:2019-12-25 07:51:25
【问题描述】:

我使用cloudformation 来启动一个 ec2 实例。下面是cloudformation模板:

Parameters:
  KeyName:
    Description: The EC2 Key Pair to allow SSH access to the instance
    Type: 'AWS::EC2::KeyPair::KeyName'
Resources:
  Ec2Instance:
    Type: 'AWS::EC2::SpotFleet'
    Properties:
      SecurityGroups:
        - !Ref InstanceSecurityGroup
        - MyExistingSecurityGroup
      KeyName: !Ref KeyName
      ImageId: ami-07d0cf3af28718ef8
      InstanceType: p2.8xlarge
      AllocationStrategy: lowestPrice
      SpotPrice: 1
  InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: Enable SSH access via port 22
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '22'
          ToPort: '22'
          CidrIp: 0.0.0.0/0

我在 cloudformation 中创建了一个堆栈,并从 key pair 的下拉列表中指定了 Key Name。在堆栈回滚之后,我看到此错误消息Encountered unsupported property KeyName。我想知道我的配置有什么问题?

【问题讨论】:

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


    【解决方案1】:

    查看AWS::EC2::SpotFleet 上的文档。它只支持SpotFleetRequestConfigData 作为属性。

    您可能需要指定如下内容:

      Ec2Instance:
        Type: 'AWS::EC2::SpotFleet'
        Properties:
          SpotFleetRequestConfigData:
            SpotPrice: 1
            AllocationStrategy: lowestPrice
            LaunchSpecifications:
            - InstanceType: p2.8xlarge
              SecurityGroups:
              - !Ref InstanceSecurityGroup
              - MyExistingSecurityGroup
              KeyName: !Ref KeyName
              ImageId: ami-07d0cf3af28718ef8
    

    查看AWS::EC2::SpotFleet 文档,它有一个非常详细的示例。

    【讨论】:

    • 谢谢。我认为是的。但是为什么它没有给出合理的错误信息呢?
    • @ZhaoYi 嗯,在某种意义上确实如此。错误消息表明KeyName 不在正确的位置。但是给出一个关于它实际上应该在哪里的提示可能太多了。
    猜你喜欢
    • 2019-12-29
    • 2019-02-03
    • 2023-04-02
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2016-05-29
    • 1970-01-01
    相关资源
    最近更新 更多