Skip to content

Commit 283df73

Browse files
aws5295yob
authored andcommitted
yml templates/aws-stack: Add Mixed Instance support to the ASG
1 parent 061e549 commit 283df73

File tree

1 file changed

+91
-4
lines changed

1 file changed

+91
-4
lines changed

templates/aws-stack.yml

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ Metadata:
5757
Parameters:
5858
- MinSize
5959
- MaxSize
60+
- SpotAllocationStrategy
61+
- OnDemandBaseCapacity
62+
- OnDemandPercentageAboveBaseCapacity
63+
- InstanceType1
64+
- InstanceType2
65+
- InstanceType3
66+
- InstanceType4
6067
- ScaleOutFactor
6168
- ScaleInIdlePeriod
6269
- ScaleOutForWaitingJobs
@@ -210,7 +217,7 @@ Parameters:
210217
MinLength: 1
211218

212219
SpotPrice:
213-
Description: Spot bid price to use for the instances. 0 means normal (non-spot) instances
220+
Description: Maximum Spot bid price to use for the instances. 0 allows you to specify mixed instances (a combination of On-Demand and Spot Instances across multiple instances types)
214221
Type: String
215222
Default: 0
216223

@@ -225,6 +232,44 @@ Parameters:
225232
Type: Number
226233
Default: 0
227234

235+
InstanceType1:
236+
Description: The primary instance type to use when requesting mixed instance types.
237+
Type: String
238+
Default: ""
239+
240+
InstanceType2:
241+
Description: The secondary instance type to use when requesting mixed instances. Omit this parmameter to only request 1 instance type.
242+
Type: String
243+
Default: ""
244+
245+
InstanceType3:
246+
Description: The tertiary instance type to use when requesting mixed instances. Omit this parmameter to only request 2 instance types.
247+
Type: String
248+
Default: ""
249+
250+
InstanceType4:
251+
Description: The quaternary instance type to use when requesting mixed instances. Omit this parmameter to only request 3 instance types.
252+
Type: String
253+
Default: ""
254+
255+
SpotAllocationStrategy:
256+
Description: Indicates how to allocate Spot capacity across Spot pools.
257+
AllowedValues:
258+
- capacity-optimized
259+
- lowest-price
260+
Type: String
261+
Default: capacity-optimized
262+
263+
OnDemandBaseCapacity:
264+
Description: Minimum number of instances in the ASG's initial capacity that must be fulfilled by On-Demand instances.
265+
Type: Number
266+
Default: 0
267+
268+
OnDemandPercentageAboveBaseCapacity:
269+
Description: Percentage of On-Demand Instances for additional capacity beyond the optional On-Demand base amount.
270+
Type: Number
271+
Default: 40
272+
228273
ScaleOutFactor:
229274
Description: A decimal factor to apply to scale out changes to speed up or slow down scale-out
230275
Type: Number
@@ -446,6 +491,18 @@ Conditions:
446491
UseDefaultRootVolumeName:
447492
!Equals [ !Ref RootVolumeName, "" ]
448493

494+
UseInstanceType1:
495+
!Not [ !Equals [ !Ref InstanceType1, ""] ]
496+
497+
UseInstanceType2:
498+
!Not [ !Equals [ !Ref InstanceType2, ""] ]
499+
500+
UseInstanceType3:
501+
!Not [ !Equals [ !Ref InstanceType3, ""] ]
502+
503+
UseInstanceType4:
504+
!Not [ !Equals [ !Ref InstanceType4, ""] ]
505+
449506
UseManagedPolicyARN:
450507
!Not [ !Equals [ !Join [ "", !Ref ManagedPolicyARN ], "" ] ]
451508

@@ -914,9 +971,39 @@ Resources:
914971
Type: AWS::AutoScaling::AutoScalingGroup
915972
Properties:
916973
VPCZoneIdentifier: !If [ "CreateVpcResources", [ !Ref Subnet0, !Ref Subnet1 ], !Ref Subnets ]
917-
LaunchTemplate:
918-
LaunchTemplateId: !Ref AgentLaunchTemplate
919-
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
974+
MixedInstancesPolicy: !If
975+
- UseSpotInstances
976+
- !Ref "AWS::NoValue"
977+
- InstancesDistribution:
978+
OnDemandBaseCapacity: !Ref OnDemandBaseCapacity
979+
OnDemandPercentageAboveBaseCapacity: !Ref OnDemandPercentageAboveBaseCapacity
980+
SpotAllocationStrategy: !Ref SpotAllocationStrategy
981+
LaunchTemplate:
982+
LaunchTemplateSpecification:
983+
LaunchTemplateId: !Ref AgentLaunchTemplate
984+
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
985+
Overrides:
986+
- InstanceType: !If
987+
- UseInstanceType1
988+
- !Ref InstanceType1
989+
- !Ref InstanceType
990+
- InstanceType: !If
991+
- UseInstanceType2
992+
- !Ref InstanceType2
993+
- !Ref "AWS::NoValue"
994+
- InstanceType: !If
995+
- UseInstanceType3
996+
- !Ref InstanceType3
997+
- !Ref "AWS::NoValue"
998+
- InstanceType: !If
999+
- UseInstanceType4
1000+
- !Ref InstanceType4
1001+
- !Ref "AWS::NoValue"
1002+
LaunchTemplate: !If
1003+
- UseSpotInstances
1004+
- LaunchTemplateId: !Ref AgentLaunchTemplate
1005+
Version: !GetAtt "AgentLaunchTemplate.LatestVersionNumber"
1006+
- !Ref "AWS::NoValue"
9201007
MinSize: !Ref MinSize
9211008
MaxSize: !Ref MaxSize
9221009
Cooldown: 0

0 commit comments

Comments
 (0)