# ScalableTaskCount

The scalable attribute representing task count.

Extends: Construct › BaseScalableAttribute › ScalableTaskCount
Implements: IEnvironmentAware, IScalableTargetRef, IConstruct, IDependable

- Source: [`aws-ecs/lib/base/scalable-task-count.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-ecs/lib/base/scalable-task-count.ts#L16)

## Example

```ts
declare const cluster: ecs.Cluster;
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  desiredCount: 1,
  cpu: 512,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
  },
  minHealthyPercent: 100,
});

const scalableTarget = loadBalancedFargateService.service.autoScaleTaskCount({
  minCapacity: 1,
  maxCapacity: 20,
});

scalableTarget.scaleOnCpuUtilization('CpuScaling', {
  targetUtilizationPercent: 50,
});

scalableTarget.scaleOnMemoryUtilization('MemoryScaling', {
  targetUtilizationPercent: 50,
});
```

## Initializer

```ts
new ScalableTaskCount(scope: Construct, id: string, props: ScalableTaskCountProps)
```

## Construct Props

- `dimension`: string (required) — Scalable dimension of the attribute.

- `maxCapacity`: number (required) — Maximum capacity to scale to.

- `minCapacity`: number = 1 — Minimum capacity to scale to.

- `resourceId`: string (required) — Resource ID of the attribute.

- `role`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) (required) — Role to use for scaling.

- `serviceNamespace`: [ServiceNamespace](/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.ServiceNamespace.html) (required) — Service namespace of the scalable attribute.

## Properties

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

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

- `scalableTargetRef`: [ScalableTargetReference](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_applicationautoscaling.ScalableTargetReference.html) — A reference to a ScalableTarget resource.

## Methods

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

- `scaleOnCpuUtilization(id: string, props: CpuUtilizationScalingProps): void` — Scales in or out to achieve a target CPU utilization.

- `scaleOnMemoryUtilization(id: string, props: MemoryUtilizationScalingProps): void` — Scales in or out to achieve a target memory utilization.

- `scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): void` — Scales in or out based on a specified metric value.

- `scaleOnRequestCount(id: string, props: RequestCountScalingProps): void` — Scales in or out to achieve a target Application Load Balancer request count per target.

- `scaleOnSchedule(id: string, props: ScalingSchedule): void` — Scales in or out based on a specified scheduled time.

- `scaleToTrackCustomMetric(id: string, props: TrackCustomMetricProps): void` — Scales in or out to achieve a target on a custom metric.

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