CapacityProviderOptions Class
Capacity provider options.
| Source | aws-stepfunctions-tasks/lib/ecs/run-task.ts |
|---|---|
| Type last changed |
Example
ts
const vpc = ec2.Vpc.fromLookup(this, 'Vpc', {
isDefault: true,
});
const cluster = new ecs.Cluster(this, 'FargateCluster', { vpc });
const taskDefinition = new ecs.TaskDefinition(this, 'TD', {
memoryMiB: '512',
cpu: '256',
compatibility: ecs.Compatibility.FARGATE,
});
// Use custom() option - specify custom capacity provider strategy
const runTaskWithCustom = new tasks.EcsRunTask(this, 'RunTaskWithCustom', {
cluster,
taskDefinition,
launchTarget: new tasks.EcsFargateLaunchTarget({
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
capacityProviderOptions: tasks.CapacityProviderOptions.custom([
{ capacityProvider: 'FARGATE_SPOT', weight: 2, base: 1 },
{ capacityProvider: 'FARGATE', weight: 1 },
]),
}),
});
// Use default() option - uses cluster's default capacity provider strategy
const runTaskWithDefault = new tasks.EcsRunTask(this, 'RunTaskWithDefault', {
cluster,
taskDefinition,
launchTarget: new tasks.EcsFargateLaunchTarget({
platformVersion: ecs.FargatePlatformVersion.VERSION1_4,
capacityProviderOptions: tasks.CapacityProviderOptions.default(),
}),
});
python
vpc = ec2.Vpc.from_lookup(self, "Vpc",
is_default=True
)
cluster = ecs.Cluster(self, "FargateCluster", vpc=vpc)
task_definition = ecs.TaskDefinition(self, "TD",
memory_mi_b="512",
cpu="256",
compatibility=ecs.Compatibility.FARGATE
)
# Use custom() option - specify custom capacity provider strategy
run_task_with_custom = tasks.EcsRunTask(self, "RunTaskWithCustom",
cluster=cluster,
task_definition=task_definition,
launch_target=tasks.EcsFargateLaunchTarget(
platform_version=ecs.FargatePlatformVersion.VERSION1_4,
capacity_provider_options=tasks.CapacityProviderOptions.custom([capacity_provider="FARGATE_SPOT", weight=2, base=1, capacity_provider="FARGATE", weight=1
])
)
)
# Use default() option - uses cluster's default capacity provider strategy
run_task_with_default = tasks.EcsRunTask(self, "RunTaskWithDefault",
cluster=cluster,
task_definition=task_definition,
launch_target=tasks.EcsFargateLaunchTarget(
platform_version=ecs.FargatePlatformVersion.VERSION1_4,
capacity_provider_options=tasks.CapacityProviderOptions.default()
)
)
java
IVpc vpc = Vpc.fromLookup(this, "Vpc", VpcLookupOptions.builder()
.isDefault(true)
.build());
Cluster cluster = Cluster.Builder.create(this, "FargateCluster").vpc(vpc).build();
TaskDefinition taskDefinition = TaskDefinition.Builder.create(this, "TD")
.memoryMiB("512")
.cpu("256")
.compatibility(Compatibility.FARGATE)
.build();
// Use custom() option - specify custom capacity provider strategy
EcsRunTask runTaskWithCustom = EcsRunTask.Builder.create(this, "RunTaskWithCustom")
.cluster(cluster)
.taskDefinition(taskDefinition)
.launchTarget(EcsFargateLaunchTarget.Builder.create()
.platformVersion(FargatePlatformVersion.VERSION1_4)
.capacityProviderOptions(CapacityProviderOptions.custom(List.of(CapacityProviderStrategy.builder().capacityProvider("FARGATE_SPOT").weight(2).base(1).build(), CapacityProviderStrategy.builder().capacityProvider("FARGATE").weight(1).build())))
.build())
.build();
// Use default() option - uses cluster's default capacity provider strategy
EcsRunTask runTaskWithDefault = EcsRunTask.Builder.create(this, "RunTaskWithDefault")
.cluster(cluster)
.taskDefinition(taskDefinition)
.launchTarget(EcsFargateLaunchTarget.Builder.create()
.platformVersion(FargatePlatformVersion.VERSION1_4)
.capacityProviderOptions(CapacityProviderOptions.default())
.build())
.build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var vpc = Vpc.FromLookup(this, "Vpc", new VpcLookupOptions {
IsDefault = true
});
var cluster = new Cluster(this, "FargateCluster", new ClusterProps { Vpc = vpc });
var taskDefinition = new TaskDefinition(this, "TD", new TaskDefinitionProps {
MemoryMiB = "512",
Cpu = "256",
Compatibility = Compatibility.FARGATE
});
// Use custom() option - specify custom capacity provider strategy
var runTaskWithCustom = new EcsRunTask(this, "RunTaskWithCustom", new EcsRunTaskProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
LaunchTarget = new EcsFargateLaunchTarget(new EcsFargateLaunchTargetOptions {
PlatformVersion = FargatePlatformVersion.VERSION1_4,
CapacityProviderOptions = CapacityProviderOptions.Custom(new [] { new CapacityProviderStrategy { CapacityProvider = "FARGATE_SPOT", Weight = 2, Base = 1 }, new CapacityProviderStrategy { CapacityProvider = "FARGATE", Weight = 1 } })
})
});
// Use default() option - uses cluster's default capacity provider strategy
var runTaskWithDefault = new EcsRunTask(this, "RunTaskWithDefault", new EcsRunTaskProps {
Cluster = cluster,
TaskDefinition = taskDefinition,
LaunchTarget = new EcsFargateLaunchTarget(new EcsFargateLaunchTargetOptions {
PlatformVersion = FargatePlatformVersion.VERSION1_4,
CapacityProviderOptions = CapacityProviderOptions.Default()
})
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
vpc := ec2.Vpc_FromLookup(this, jsii.String("Vpc"), &VpcLookupOptions{
IsDefault: jsii.Boolean(true),
})
cluster := ecs.NewCluster(this, jsii.String("FargateCluster"), &ClusterProps{
Vpc: Vpc,
})
taskDefinition := ecs.NewTaskDefinition(this, jsii.String("TD"), &TaskDefinitionProps{
MemoryMiB: jsii.String("512"),
Cpu: jsii.String("256"),
Compatibility: ecs.Compatibility_FARGATE,
})
// Use custom() option - specify custom capacity provider strategy
runTaskWithCustom := tasks.NewEcsRunTask(this, jsii.String("RunTaskWithCustom"), &EcsRunTaskProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
LaunchTarget: tasks.NewEcsFargateLaunchTarget(&EcsFargateLaunchTargetOptions{
PlatformVersion: ecs.FargatePlatformVersion_VERSION1_4,
CapacityProviderOptions: tasks.CapacityProviderOptions_Custom([]CapacityProviderStrategy{
&CapacityProviderStrategy{
CapacityProvider: jsii.String("FARGATE_SPOT"),
Weight: jsii.Number(2),
Base: jsii.Number(1),
},
&CapacityProviderStrategy{
CapacityProvider: jsii.String("FARGATE"),
Weight: jsii.Number(1),
},
}),
}),
})
// Use default() option - uses cluster's default capacity provider strategy
runTaskWithDefault := tasks.NewEcsRunTask(this, jsii.String("RunTaskWithDefault"), &EcsRunTaskProps{
Cluster: Cluster,
TaskDefinition: TaskDefinition,
LaunchTarget: tasks.NewEcsFargateLaunchTarget(&EcsFargateLaunchTargetOptions{
PlatformVersion: ecs.FargatePlatformVersion_VERSION1_4,
CapacityProviderOptions: tasks.CapacityProviderOptions_Default(),
}),
})
Methods
custom(capacityProviderStrategy: CapacityProviderStrategy[]): CapacityProviderOptions // chainable@staticmethod def custom(capacity_provider_strategy: typing.List[CapacityProviderStrategy]) -> CapacityProviderOptionspublic static CapacityProviderOptions custom(List<CapacityProviderStrategy> capacityProviderStrategy)public static CapacityProviderOptions Custom(CapacityProviderStrategy[] capacityProviderStrategy)func Custom(CapacityProviderStrategy *[]CapacityProviderStrategy) CapacityProviderOptions static #Use a custom capacity provider strategy.
You can specify between 1 and 20 capacity providers.
1 parameter
Parameters
capacityProviderStrategycapacity_provider_strategycapacityProviderStrategycapacityProviderStrategyCapacityProviderStrategy— The capacity provider strategy to use for the task.
default(): CapacityProviderOptions // chainable@staticmethod def default() -> CapacityProviderOptionspublic static CapacityProviderOptions default()public static CapacityProviderOptions Default()func Default() CapacityProviderOptions static #Use the cluster's default capacity provider strategy.