Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Windows spot instance with persistence request using cloudformation

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading