# CapacityProviderOptions

Capacity provider options.

- Source: [`aws-stepfunctions-tasks/lib/ecs/run-task.ts`](https://github.com/aws/aws-cdk/blob/v2.273.0/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/ecs/run-task.ts#L219)
- Type last changed: v2.234.0 · 8 Jan 2026

## 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(),
  }),
});
```

## Methods

- `custom(capacityProviderStrategy: CapacityProviderStrategy[]): CapacityProviderOptions // chainable` (static) — Use a custom capacity provider strategy.

  You can specify between 1 and 20 capacity providers.

  **Parameters**

  - `capacityProviderStrategy` — The capacity provider strategy to use for the task.

- `default(): CapacityProviderOptions // chainable` (static) — Use the cluster's default capacity provider strategy.
