Skip to content

Commit eb6fd03

Browse files
authored
chore(autoscaling): add price-capacity-optimized (#23232)
add price-capacity-optimized to SpotAllocationStrategy enum ref https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-autoscaling-autoscalinggroup-instancesdistribution.html#cfn-autoscaling-autoscalinggroup-instancesdistribution-spotallocationstrategy fixed #23226 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Construct Runtime Dependencies: * [ ] This PR adds new construct runtime dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-construct-runtime-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 16d9387 commit eb6fd03

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ export enum SpotAllocationStrategy {
408408
* honors the instance type priorities on a best-effort basis but optimizes for capacity first.
409409
*/
410410
CAPACITY_OPTIMIZED_PRIORITIZED = 'capacity-optimized-prioritized',
411+
412+
/**
413+
* The price and capacity optimized allocation strategy looks at both price and
414+
* capacity to select the Spot Instance pools that are the least likely to be
415+
* interrupted and have the lowest possible price.
416+
*/
417+
PRICE_CAPACITY_OPTIMIZED = 'price-capacity-optimized',
411418
}
412419

413420
/**

packages/@aws-cdk/aws-autoscaling/test/auto-scaling-group.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,47 @@ test('can use Vpc imported from unparseable list tokens', () => {
19151915
});
19161916
});
19171917

1918+
test('add price-capacity-optimized', () => {
1919+
// GIVEN
1920+
const stack = new cdk.Stack();
1921+
1922+
// WHEN
1923+
const lt = LaunchTemplate.fromLaunchTemplateAttributes(stack, 'imported-lt', {
1924+
launchTemplateId: 'test-lt-id',
1925+
versionNumber: '0',
1926+
});
1927+
1928+
new autoscaling.AutoScalingGroup(stack, 'mip-asg', {
1929+
mixedInstancesPolicy: {
1930+
launchTemplate: lt,
1931+
launchTemplateOverrides: [{
1932+
instanceType: new InstanceType('t4g.micro'),
1933+
launchTemplate: lt,
1934+
weightedCapacity: 9,
1935+
}],
1936+
instancesDistribution: {
1937+
onDemandAllocationStrategy: OnDemandAllocationStrategy.PRIORITIZED,
1938+
onDemandBaseCapacity: 1,
1939+
onDemandPercentageAboveBaseCapacity: 2,
1940+
spotAllocationStrategy: SpotAllocationStrategy.PRICE_CAPACITY_OPTIMIZED,
1941+
spotInstancePools: 3,
1942+
spotMaxPrice: '4',
1943+
},
1944+
},
1945+
vpc: mockVpc(stack),
1946+
});
1947+
1948+
// THEN
1949+
Template.fromStack(stack).hasResourceProperties('AWS::AutoScaling::AutoScalingGroup', {
1950+
MixedInstancesPolicy: {
1951+
InstancesDistribution: {
1952+
SpotAllocationStrategy: 'price-capacity-optimized',
1953+
},
1954+
},
1955+
});
1956+
});
1957+
1958+
19181959
function mockSecurityGroup(stack: cdk.Stack) {
19191960
return ec2.SecurityGroup.fromSecurityGroupId(stack, 'MySG', 'most-secure');
19201961
}

0 commit comments

Comments
 (0)