Skip to content
v2.278.0

EcsFargateLaunchTargetOptions Struct ​

Properties to define an ECS service.

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([ecs.CapacityProviderStrategy(capacity_provider="FARGATE_SPOT", weight=2, base=1), ecs.CapacityProviderStrategy(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(),
	}),
})

Properties ​

capacityProviderOptionsoptionalCapacityProviderOptionscapacity_provider_optionsoptionalCapacityProviderOptionscapacityProviderOptionsoptionalCapacityProviderOptionsCapacityProviderOptionsoptionalCapacityProviderOptionsCapacityProviderOptionsoptionalCapacityProviderOptions #
The capacity provider options to use for the task.

Default: 'FARGATE' LaunchType running tasks on AWS Fargate On-Demand infrastructure is used without the capacity provider strategy.

notes

This property allows you to set the capacity provider strategy for the task.

If you want to set the capacity provider strategy for the task, specify CapacityProviderOptions.custom(). This is required to use the FARGATE_SPOT capacity provider.

If you want to use the cluster's default capacity provider strategy, specify CapacityProviderOptions.default().

platformVersionFargatePlatformVersionplatform_versionFargatePlatformVersionplatformVersionFargatePlatformVersionPlatformVersionFargatePlatformVersionPlatformVersionFargatePlatformVersion required #
Refers to a specific runtime environment for Fargate task infrastructure.

Fargate platform version is a combination of the kernel and container runtime versions.