amazon-web-servicesaws-cloudformationspot-instances

aws cloudformation template for spot request in ec2 instance


I need a sample cloud formation template to add spot requests while provisioning the ec2 instance in AWS.I have tried with console to provision spot instances but I couldn't find any exact template for add spot request in ec2


Solution

  • You Can create a SpotFleet resource, here's an example

    SpotFleet:
     Type: AWS::EC2::SpotFleet
     Properties:
       SpotFleetRequestConfigData:
         IamFleetRole: !GetAtt [IAMFleetRole, Arn]
         SpotPrice: '1000'
         TargetCapacity:
           Ref: TargetCapacity
         LaunchSpecifications:
         - EbsOptimized: 'false'
           InstanceType:
             Ref: InstanceType
         ImageId:
           Fn::FindInMap:
           - AWSRegionArch2AMI
           - Ref: AWS::Region
           - Fn::FindInMap:
             - AWSInstanceType2Arch
             - Ref: InstanceType
             - Arch
         SubnetId:
           Ref: Subnet1
         WeightedCapacity: '8'
       - EbsOptimized: 'true'
         InstanceType:
           Ref: InstanceType
         ImageId:
           Fn::FindInMap:
           - AWSRegionArch2AMI
           - Ref: AWS::Region
           - Fn::FindInMap:
           - AWSInstanceType2Arch
           - Ref: InstanceType
           - Arch
         Monitoring:
           Enabled: 'true'
           SecurityGroups:
            - GroupId:
                Fn::GetAtt:
                - SG0
                - GroupId
          SubnetId:
             Ref: Subnet0
          IamInstanceProfile:
            Arn:
            Fn::GetAtt:
            - RootInstanceProfile
            - Arn
          WeightedCapacity: '8'