Skip to content

Commit 94003ec

Browse files
authored
feat(stepfunctions-tasks): additional allocation strategies for spot instance fleets in EmrCreateCluster (#28525)
This PR adds new allocation strategies for spot instance fleets in EmrCreateCluster. - price-capacity-optimized - recommended - lowest-price - diversified https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-emr-instancefleetconfig-spotprovisioningspecification.html https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-allocation-strategy.html ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e0b725c commit 94003ec

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/emr/emr-create-cluster.ts

+14
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,20 @@ export namespace EmrCreateCluster {
684684
* Capacity-optimized, which launches instances from Spot Instance pools with optimal capacity for the number of instances that are launching.
685685
*/
686686
CAPACITY_OPTIMIZED = 'capacity-optimized',
687+
/**
688+
* Price-capacity-optimized, which launches instances from Spot Instance pools with the highest capacity availability for the number of instances that are launching.
689+
*
690+
* Recommended.
691+
*/
692+
PRICE_CAPACITY_OPTIMIZED = 'price-capacity-optimized',
693+
/**
694+
* Lowest-price, which launches instances from the lowest priced pool that has available capacity.
695+
*/
696+
LOWEST_PRICE = 'lowest-price',
697+
/**
698+
* Diversified, which launches instances across all Spot capacity pools.
699+
*/
700+
DIVERSIFIED = 'diversified',
687701
}
688702

689703
/**

packages/aws-cdk-lib/aws-stepfunctions-tasks/test/emr/emr-create-cluster.test.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Template, Match } from '../../../assertions';
1+
import { Template } from '../../../assertions';
22
import * as iam from '../../../aws-iam';
33
import * as sfn from '../../../aws-stepfunctions';
44
import * as cdk from '../../../core';
@@ -883,7 +883,12 @@ test('Create Cluster with Instances configuration', () => {
883883
});
884884
});
885885

886-
test('Create Cluster with InstanceFleet with allocation strategy=capacity-optimized for Spot instances', () => {
886+
test.each([
887+
[EmrCreateCluster.SpotAllocationStrategy.CAPACITY_OPTIMIZED, 'capacity-optimized'],
888+
[EmrCreateCluster.SpotAllocationStrategy.PRICE_CAPACITY_OPTIMIZED, 'price-capacity-optimized'],
889+
[EmrCreateCluster.SpotAllocationStrategy.LOWEST_PRICE, 'lowest-price'],
890+
[EmrCreateCluster.SpotAllocationStrategy.DIVERSIFIED, 'diversified'],
891+
])('Create Cluster with InstanceFleet with allocation strategy %s for Spot instances', (strategy, expected) => {
887892
// WHEN
888893
const task = new EmrCreateCluster(stack, 'Task', {
889894
instances: {
@@ -913,7 +918,7 @@ test('Create Cluster with InstanceFleet with allocation strategy=capacity-optimi
913918
}],
914919
launchSpecifications: {
915920
spotSpecification: {
916-
allocationStrategy: EmrCreateCluster.SpotAllocationStrategy.CAPACITY_OPTIMIZED,
921+
allocationStrategy: strategy,
917922
blockDurationMinutes: 1,
918923
timeoutAction: EmrCreateCluster.SpotTimeoutAction.TERMINATE_CLUSTER,
919924
timeoutDurationMinutes: 5,
@@ -975,7 +980,7 @@ test('Create Cluster with InstanceFleet with allocation strategy=capacity-optimi
975980
}],
976981
LaunchSpecifications: {
977982
SpotSpecification: {
978-
AllocationStrategy: 'capacity-optimized',
983+
AllocationStrategy: expected,
979984
BlockDurationMinutes: 1,
980985
TimeoutAction: 'TERMINATE_CLUSTER',
981986
TimeoutDurationMinutes: 5,

0 commit comments

Comments
 (0)