# ClusterProps

The properties used to define an ECS cluster.

Extends: ClusterProps
Used as props by: Cluster

- Source: [`aws-ecs/lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ecs/lib/cluster.ts#L55)
- Type last changed: v2.176.0 · 15 Jan 2025

## Example

```ts
declare const vpc: ec2.Vpc;

const cluster = new ecs.Cluster(this, 'Cluster', {
  vpc,
});

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  instanceType: new ec2.InstanceType('t2.micro'),
  machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
  minCapacity: 0,
  maxCapacity: 100,
});

const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
  autoScalingGroup,
  instanceWarmupPeriod: 300,
});
cluster.addAsgCapacityProvider(capacityProvider);

const taskDefinition = new ecs.Ec2TaskDefinition(this, 'TaskDef');

taskDefinition.addContainer('web', {
  image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
  memoryReservationMiB: 256,
});

new ecs.Ec2Service(this, 'EC2Service', {
  cluster,
  taskDefinition,
  minHealthyPercent: 100,
  capacityProviderStrategies: [
    {
      capacityProvider: capacityProvider.capacityProviderName,
      weight: 1,
    },
  ],
});
```

## Properties

- `capacity`: [AddCapacityOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.AddCapacityOptions.html) — The ec2 capacity to add to the cluster.

  **Default:** no EC2 capacity will be added, you can use `addCapacity` to add capacity later.

- `clusterName`: string — The name for the cluster.

  **Default:** CloudFormation-generated name

- `containerInsights`: boolean — See {@link containerInsightsV2 }

  **Default:** Container Insights will be disabled for this cluster.

- `containerInsightsV2`: [ContainerInsights](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ContainerInsights.html) — The CloudWatch Container Insights configuration for the cluster.

  **Default:** {@link ContainerInsights.DISABLED } This may be overridden by ECS account level settings.

- `defaultCloudMapNamespace`: [CloudMapNamespaceOptions](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.CloudMapNamespaceOptions.html) — The service discovery namespace created in this cluster.

  **Default:** no service discovery namespace created, you can use `addDefaultCloudMapNamespace` to add a default service discovery namespace later.

- `enableFargateCapacityProviders`: boolean = false — Whether to enable Fargate Capacity Providers.

- `executeCommandConfiguration`: [ExecuteCommandConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ExecuteCommandConfiguration.html) — The execute command configuration for the cluster.

  **Default:** no configuration will be provided.

- `managedStorageConfiguration`: [ManagedStorageConfiguration](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ManagedStorageConfiguration.html) — Encryption configuration for ECS Managed storage.

  **Default:** no encryption will be applied.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) — The VPC where your ECS instances will be running or your ENIs will be deployed.

  **Default:** creates a new VPC with two AZs
