# Compatibility

The task launch type compatibility requirement.

- Source: [`aws-ecs/lib/base/task-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ecs/lib/base/task-definition.ts#L1366)
- Type last changed: v2.219.0 · 1 Oct 2025

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

## Members

| Member | Description |
| --- | --- |
| `EC2` | The task should specify the EC2 launch type. |
| `FARGATE` | The task should specify the Fargate launch type. |
| `EC2_AND_FARGATE` | The task can specify either the EC2 or Fargate launch types. |
| `EXTERNAL` | The task should specify the External launch type. |
| `MANAGED_INSTANCES` | The task should specify the Managed Instances launch type. |
| `EC2_AND_MANAGED_INSTANCES` | The task can specify either the EC2 or Managed Instances launch types. |
| `FARGATE_AND_MANAGED_INSTANCES` | The task can specify either the Fargate or Managed Instances launch types. |
| `FARGATE_AND_EC2_AND_MANAGED_INSTANCES` | The task can specify either the Fargate, EC2 or Managed Instances launch types. |

## Referenced by

- [`ITaskDefinition`](/v2/docs/aws-cdk-lib.aws_ecs.ITaskDefinition).compatibility
- [`TaskDefinition`](/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinition).compatibility
- [`TaskDefinitionAttributes`](/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinitionAttributes).compatibility
- [`TaskDefinitionProps`](/v2/docs/aws-cdk-lib.aws_ecs.TaskDefinitionProps).compatibility
