# ManagedInstancesCapacityProvider

A Managed Instances Capacity Provider.

This allows an ECS cluster to use
Managed Instances for task placement with managed infrastructure.

Extends: Construct › ManagedInstancesCapacityProvider
Implements: IConnectable, IConstruct, IDependable

- Source: [`aws-ecs/lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0/packages/aws-cdk-lib/aws-ecs/lib/cluster.ts#L1698)
- Type last changed: v2.234.0 · 8 Jan 2026

## Example

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

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

const securityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', {
  vpc,
  description: 'Security group for managed instances',
});

const miCapacityProvider = new ecs.ManagedInstancesCapacityProvider(this, 'MICapacityProvider', {
  capacityOptionType: ecs.CapacityOptionType.SPOT,
  subnets: vpc.privateSubnets,
  securityGroups: [securityGroup],
  instanceRequirements: {
    vCpuCountMin: 1,
    memoryMin: Size.gibibytes(2),
  },
});

// Optionally configure security group rules using IConnectable interface
miCapacityProvider.connections.allowFrom(ec2.Peer.ipv4(vpc.vpcCidrBlock), ec2.Port.tcp(80));

// Add the capacity provider to the cluster
cluster.addManagedInstancesCapacityProvider(miCapacityProvider);

const taskDefinition = new ecs.TaskDefinition(this, 'TaskDef', {
  memoryMiB: '512',
  cpu: '256',
  networkMode: ecs.NetworkMode.AWS_VPC,
  compatibility: ecs.Compatibility.MANAGED_INSTANCES,
});

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

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

## Initializer

```ts
new ManagedInstancesCapacityProvider(scope: Construct, id: string, props: ManagedInstancesCapacityProviderProps)
```

## Construct Props

- `capacityOptionType`: [CapacityOptionType](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.CapacityOptionType.html) = `ON_DEMAND` — Specifies the capacity option type for instances launched by this capacity provider.

  This determines whether instances are launched as On-Demand or Spot instances.

- `capacityProviderName`: string — The name of the capacity provider.

  **Default:** CloudFormation-generated name

  If a name is specified, it cannot start with `aws`, `ecs`, or `fargate`.
  If no name is specified, a default name in the CFNStackName-CFNResourceName-RandomString format is used.
  If the stack name starts with `aws`, `ecs`, or `fargate`, a unique resource name
  is generated that starts with `cp-`.

- `ec2InstanceProfile`: [IInstanceProfile](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IInstanceProfile.html) — The EC2 instance profile that will be attached to instances launched by this capacity provider.

  **Default:** A new instance profile prefixed with 'ecsInstanceRole' will be created

  This instance profile must contain the necessary IAM permissions for ECS container instances
  to register with the cluster and run tasks. At minimum, it should include permissions for
  ECS agent communication, ECR image pulling, and CloudWatch logging.

  If you are using Amazon ECS Managed Instances with the AWS-managed Infrastructure policy (`AmazonECSInfrastructureRolePolicyForManagedInstances`),
  the instance profile must be prefixed with `ecsInstanceRole` for the built in PassRole policy to apply.

  If you are using a custom policy for the Infrastructure role, the instance profile can have an alternative name.

- `infrastructureRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM role that ECS uses to manage the infrastructure for the capacity provider.

  **Default:** A new role will be created with the AmazonECSInfrastructureRolePolicyForManagedInstances managed policy

  This role is used by ECS to perform actions such as launching and terminating instances,
  managing Auto Scaling Groups, and other infrastructure operations required for the
  managed instances capacity provider.

- `instanceRequirements`: [InstanceRequirementsConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InstanceRequirementsConfig.html) — The instance requirements configuration for EC2 instance selection.

  **Default:** no specific instance requirements, ECS will choose appropriate instances

  This allows you to specify detailed requirements for instance selection including
  vCPU count ranges, memory ranges, CPU manufacturers (Intel, AMD, AWS Graviton),
  instance generations, network performance requirements, and many other criteria.
  ECS will automatically select appropriate instance types that meet these requirements.

- `monitoring`: [InstanceMonitoring](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.InstanceMonitoring.html) — The CloudWatch monitoring configuration for the EC2 instances.

  **Default:** no enhanced monitoring (basic monitoring only)

  Determines the granularity of CloudWatch metrics collection for the instances.
  Detailed monitoring incurs additional costs but provides better observability.

- `propagateTags`: [PropagateManagedInstancesTags](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.PropagateManagedInstancesTags.html) — Specifies whether to propagate tags from the capacity provider to the launched instances.

  **Default:** PropagateManagedInstancesTags.NONE - no tag propagation

  When set to CAPACITY_PROVIDER, tags applied to the capacity provider resource will be
  automatically applied to all EC2 instances launched by this capacity provider.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] (required) — The security groups to associate with the launched EC2 instances.

  These security groups control the network traffic allowed to and from the instances.

- `subnets`: [ISubnet](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISubnet.html)[] (required) — The VPC subnets where EC2 instances will be launched.

  This array must be non-empty and should contain subnets from the VPC where you want
  the managed instances to be deployed.

- `taskVolumeStorage`: [Size](/cdk/api/v2/docs/aws-cdk-lib.Size.html) = Size.gibibytes(80) — The size of the task volume storage attached to each instance.

  This storage is used for container images, container logs, and temporary files.
  Larger storage may be needed for workloads with large container images or
  applications that generate significant temporary data.

## Properties

- `capacityProviderName`: string (required) — Capacity provider name.

- `cluster`: [ICluster](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.ICluster.html) — The cluster this capacity provider is associated with.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) (required) — The network connections associated with this resource.

- `ec2InstanceProfile`: [IInstanceProfile](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IInstanceProfile.html) (required) — The EC2 instance profile attached to instances launched by this capacity provider.

- `infrastructureRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) (required) — The IAM role that ECS uses to manage the infrastructure for the capacity provider.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

## Methods

- `bind(cluster: ICluster): void` — Associates the capacity provider with the specified cluster.

  This method is called by the cluster when adding the capacity provider.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
