Skip to content

Commit

Permalink
chore(autoscaling): add lowest-price OnDemandAllocationStrategy enum …
Browse files Browse the repository at this point in the history
…to aws-autoscaling (#28396)

Closes #28395

Adds the On-Demand `lowest-price` allocation strategy enum for aws-autoscaling. 

https://docs.aws.amazon.com/autoscaling/ec2/userguide/allocation-strategies.html#on-demand-allocation-strategy

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
bwagner5 committed Dec 18, 2023
1 parent 49358fd commit 7a721d3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ export enum OnDemandAllocationStrategy {
* so on.
*/
PRIORITIZED = 'prioritized',

/**
* This strategy uses the lowest-price instance types in each Availability Zone based on the current
* On-Demand instance price.
*
* To meet your desired capacity, you might receive On-Demand Instances of more than one instance type
* in each Availability Zone. This depends on how much capacity you request.
*/
LOWEST_PRICE = 'lowest-price',
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,43 @@ test('add price-capacity-optimized', () => {
});
});

test('add on-demand lowest-price allocation strategy', () => {
// GIVEN
const stack = new cdk.Stack();

// WHEN
const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', {
launchTemplateId: 'test-lt-id',
versionNumber: '0',
});

new autoscaling.AutoScalingGroup(stack, 'mip-asg', {
mixedInstancesPolicy: {
launchTemplate: lt,
launchTemplateOverrides: [{
instanceType: new InstanceType('t4g.micro'),
launchTemplate: lt,
weightedCapacity: 9,
}],
instancesDistribution: {
onDemandAllocationStrategy: OnDemandAllocationStrategy.LOWEST_PRICE,
onDemandBaseCapacity: 1,
onDemandPercentageAboveBaseCapacity: 100,
},
},
vpc: mockVpc(stack),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', {
MixedInstancesPolicy: {
InstancesDistribution: {
OnDemandAllocationStrategy: 'lowest-price',
},
},
});
});

test('ssm permissions adds right managed policy', () => {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 7a721d3

Please sign in to comment.