1
votes

I use cloudformation to launch a ec2 instance. Below is the cloudformation template:

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

I created a stack in cloudformation and specify the Key Name from a drop list of key pair. After than the stack rolled back and I see this error message Encountered unsupported property KeyName. I wonder what wrong with my configuration?

1

1 Answers

1
votes

Check documentation on AWS::EC2::SpotFleet. It only supports SpotFleetRequestConfigData as property.

You will probably need to specify something like:

  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

Check the AWS::EC2::SpotFleet documentation, it has a quite elaborate example.