Home > OS >  Windows spot instance with persistence request using cloudformation
Windows spot instance with persistence request using cloudformation

Time:12-08

When I try to launch windows server using this template, I get an error:

Property validation failure: [Value of property {/LaunchTemplateData} does not match type {Object}]

I used this template:

Parameters:
  1InstanceType:
    Type: String
    Default: t2.small
    AllowedValues:
      - t2.small
      - m3.medium
      - m3.xlarge
      - i3.xlarge
  2SecurityGroup:
    Type: 'AWS::EC2::SecurityGroup::Id'
  3KeyName:
    Type: 'AWS::EC2::KeyPair::KeyName'
  4LatestAmiId:
    Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
    Default: /aws/service/ami-windows-latest/Windows_Server-2016-English-Full-Base

Resources:
  Ec2LaunchTemplate:
    Type: AWS::EC2::LaunchTemplate
    Properties:
      LaunchTemplateName: WindowsDesktop
      LaunchTemplateData:
      - ImageId: !Ref 4LatestAmiId
        InstanceType: !Ref 1InstanceType
        SecurityGroups:
          - GroupId: !Ref 2SecurityGroup
        KeyName: !Ref 3KeyName
        InstanceMarketOptions:
          MarketType: spot
          SpotOptions:
            SpotInstanceType: persistent
            InstanceInterruptionBehavior: stop

Similar code works for linux servers. It seems that Windows spot instance (or template) with persistence request can not be created using cloudformation.

CodePudding user response:

The error means that your LaunchTemplateData is not an object, but it is a list in your case. This is because extra - before ImageId. So it should be:

Resources:
  Ec2LaunchTemplate:
    Type: AWS::EC2::LaunchTemplate
    Properties:
      LaunchTemplateName: WindowsDesktop
      LaunchTemplateData:
        ImageId: !Ref 4LatestAmiId
        InstanceType: !Ref 1InstanceType
        SecurityGroups:
          - GroupId: !Ref 2SecurityGroup
        KeyName: !Ref 3KeyName
        InstanceMarketOptions:
          MarketType: spot
          SpotOptions:
            SpotInstanceType: persistent
            InstanceInterruptionBehavior: stop
  • Related