# AsgCapacityProviderProps

The options for creating an Auto Scaling Group Capacity Provider.

Extends: AsgCapacityProviderProps
Extends: AddAutoScalingGroupCapacityOptions
Used as props by: AsgCapacityProvider

- 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#L1430)
- Type last changed: v2.270.0 · 17 Sep 2026

## Example

```ts
declare const vpc: ec2.Vpc;
const launchTemplate = new ec2.LaunchTemplate(this, 'ASG-LaunchTemplate', {
  instanceType: new ec2.InstanceType('t3.medium'),
  machineImage: ecs.EcsOptimizedImage.amazonLinux2(),
  userData: ec2.UserData.forLinux(),
});

const autoScalingGroup = new autoscaling.AutoScalingGroup(this, 'ASG', {
  vpc,
  mixedInstancesPolicy: {
    instancesDistribution: {
      onDemandPercentageAboveBaseCapacity: 50,
    },
    launchTemplate: launchTemplate,
  },
});

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

const capacityProvider = new ecs.AsgCapacityProvider(this, 'AsgCapacityProvider', {
  autoScalingGroup,
  machineImageType: ecs.MachineImageType.AMAZON_LINUX_2,
});

cluster.addAsgCapacityProvider(capacityProvider);
```

## Properties

- `autoScalingGroup`: [IAutoScalingGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.IAutoScalingGroup.html) (required) — The autoscaling group to add as a Capacity Provider.

  Warning: When passing an imported resource using `AutoScalingGroup.fromAutoScalingGroupName` along with `enableManagedTerminationProtection: true`,
  the `AsgCapacityProvider` construct will not be able to enforce the option `newInstancesProtectedFromScaleIn` of the `AutoScalingGroup`.
  In this case the constructor of `AsgCapacityProvider` will throw an exception.

- `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-`.

- `enableManagedDraining`: boolean — Managed instance draining facilitates graceful termination of Amazon ECS instances.

  **Default:** CloudFormation implicitly enables managed draining when not specified.

  This allows your service workloads to stop safely and be rescheduled to non-terminating instances.
  Infrastructure maintenance and updates are performed without disruptions to workloads.

  When undefined (recommended), CloudFormation will implicitly enable managed draining.
  Set to true for explicit enablement or false to explicitly disable this feature.

- `enableManagedScaling`: boolean = true — When enabled the scale-in and scale-out actions of the cluster's Auto Scaling Group will be managed for you.

  This means your cluster will automatically scale instances based on the load your tasks put on the cluster.
  For more information, see [Using Managed Scaling](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/asg-capacity-providers.html#asg-capacity-providers-managed-scaling) in the ECS Developer Guide.

- `enableManagedTerminationProtection`: boolean = true — When enabled the Auto Scaling Group will only terminate EC2 instances that no longer have running non-daemon tasks.

  Scale-in protection will be automatically enabled on instances. When all non-daemon tasks are
  stopped on an instance, ECS initiates the scale-in process and turns off scale-in protection for the
  instance. The Auto Scaling Group can then terminate the instance. For more information see [Managed termination
   protection](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-auto-scaling.html#managed-termination-protection)
  in the ECS Developer Guide.

  Managed scaling must also be enabled.

- `instanceWarmupPeriod`: number = 300 — The period of time, in seconds, after a newly launched Amazon EC2 instance can contribute to CloudWatch metrics for Auto Scaling group.

  Must be between 0 and 10000.

- `machineImageType`: [MachineImageType](/cdk/api/v2/docs/aws-cdk-lib.aws_ecs.MachineImageType.html) — What type of machine image this is.

  **Default:** Automatically determined from `machineImage`, if available, otherwise `MachineImageType.AMAZON_LINUX_2`.

  Depending on the setting, different UserData will automatically be added
  to the `AutoScalingGroup` to configure it properly for use with ECS.

  If you create an `AutoScalingGroup` yourself and are adding it via
  `addAutoScalingGroup()`, you must specify this value. If you are adding an
  `autoScalingGroup` via `addCapacity`, this value will be determined
  from the `machineImage` you pass.

- `maximumScalingStepSize`: number = 1000 — Maximum scaling step size.

  In most cases this should be left alone.

- `minimumScalingStepSize`: number = 1 — Minimum scaling step size.

  In most cases this should be left alone.

- `spotInstanceDraining`: boolean = false — Specify whether to enable Automated Draining for Spot Instances running Amazon ECS Services.

  For more information, see [Using Spot Instances](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/container-instance-spot.html).

- `targetCapacityPercent`: number = 100 — Target capacity percent.

  In most cases this should be left alone.

- `topicEncryptionKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — If `AddAutoScalingGroupCapacityOptions.taskDrainTime` is non-zero, then the ECS cluster creates an SNS Topic to as part of a system to drain instances of tasks when the instance is being shut down. If this property is provided, then this key will be used to encrypt the contents of that SNS Topic. See [SNS Data Encryption](https://docs.aws.amazon.com/sns/latest/dg/sns-data-encryption.html) for more information.

  **Default:** The SNS Topic will not be encrypted.
