# TargetTrackingScalingPolicy

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › TargetTrackingScalingPolicy
Implements: [IConstruct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.IDependable.html)
Returned by: [ScalableTarget.scaleToTrackMetric](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.ScalableTarget.html#scaletotrackmetric)

- Source: [`aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-applicationautoscaling/lib/target-tracking-scaling-policy.ts#L122)

## Example

TypeScript:

```ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_applicationautoscaling as appscaling } from 'aws-cdk-lib';
import { aws_cloudwatch as cloudwatch } from 'aws-cdk-lib';
import { aws_applicationautoscaling as interfaces_applicationautoscaling } from 'aws-cdk-lib/interfaces';

declare const metric: cloudwatch.Metric;
declare const scalableTargetRef: interfaces_applicationautoscaling.IScalableTargetRef;
const targetTrackingScalingPolicy = new appscaling.TargetTrackingScalingPolicy(this, 'MyTargetTrackingScalingPolicy', {
  scalingTarget: scalableTargetRef,
  targetValue: 123,

  // the properties below are optional
  customMetric: metric,
  disableScaleIn: false,
  policyName: 'policyName',
  predefinedMetric: appscaling.PredefinedMetric.APPSTREAM_AVERAGE_CAPACITY_UTILIZATION,
  resourceLabel: 'resourceLabel',
  scaleInCooldown: cdk.Duration.minutes(30),
  scaleOutCooldown: cdk.Duration.minutes(30),
});
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_applicationautoscaling as appscaling
from aws_cdk import aws_cloudwatch as cloudwatch
from aws_cdk.interfaces import aws_applicationautoscaling as interfaces_applicationautoscaling

# metric: cloudwatch.Metric
# scalable_target_ref: interfaces_applicationautoscaling.IScalableTargetRef

target_tracking_scaling_policy = appscaling.TargetTrackingScalingPolicy(self, "MyTargetTrackingScalingPolicy",
    scaling_target=scalable_target_ref,
    target_value=123,

    # the properties below are optional
    custom_metric=metric,
    disable_scale_in=False,
    policy_name="policyName",
    predefined_metric=appscaling.PredefinedMetric.APPSTREAM_AVERAGE_CAPACITY_UTILIZATION,
    resource_label="resourceLabel",
    scale_in_cooldown=cdk.Duration.minutes(30),
    scale_out_cooldown=cdk.Duration.minutes(30)
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.applicationautoscaling.*;
import software.amazon.awscdk.services.cloudwatch.*;
import software.amazon.awscdk.interfaces.applicationautoscaling.*;

Metric metric;
IScalableTargetRef scalableTargetRef;

TargetTrackingScalingPolicy targetTrackingScalingPolicy = TargetTrackingScalingPolicy.Builder.create(this, "MyTargetTrackingScalingPolicy")
        .scalingTarget(scalableTargetRef)
        .targetValue(123)

        // the properties below are optional
        .customMetric(metric)
        .disableScaleIn(false)
        .policyName("policyName")
        .predefinedMetric(PredefinedMetric.APPSTREAM_AVERAGE_CAPACITY_UTILIZATION)
        .resourceLabel("resourceLabel")
        .scaleInCooldown(Duration.minutes(30))
        .scaleOutCooldown(Duration.minutes(30))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK;
using Amazon.CDK.AWS.ApplicationAutoScaling;
using Amazon.CDK.AWS.CloudWatch;
using Amazon.CDK.Interfaces.ApplicationAutoScaling;

Metric metric;
IScalableTargetRef scalableTargetRef;

var targetTrackingScalingPolicy = new TargetTrackingScalingPolicy(this, "MyTargetTrackingScalingPolicy", new TargetTrackingScalingPolicyProps {
    ScalingTarget = scalableTargetRef,
    TargetValue = 123,

    // the properties below are optional
    CustomMetric = metric,
    DisableScaleIn = false,
    PolicyName = "policyName",
    PredefinedMetric = PredefinedMetric.APPSTREAM_AVERAGE_CAPACITY_UTILIZATION,
    ResourceLabel = "resourceLabel",
    ScaleInCooldown = Duration.Minutes(30),
    ScaleOutCooldown = Duration.Minutes(30)
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var metric Metric
var scalableTargetRef IScalableTargetRef

targetTrackingScalingPolicy := awscdk.Aws_applicationautoscaling.NewTargetTrackingScalingPolicy(this, jsii.String("MyTargetTrackingScalingPolicy"), &TargetTrackingScalingPolicyProps{
	ScalingTarget: scalableTargetRef,
	TargetValue: jsii.Number(123),

	// the properties below are optional
	CustomMetric: metric,
	DisableScaleIn: jsii.Boolean(false),
	PolicyName: jsii.String("policyName"),
	PredefinedMetric: awscdk.*Aws_applicationautoscaling.PredefinedMetric_APPSTREAM_AVERAGE_CAPACITY_UTILIZATION,
	ResourceLabel: jsii.String("resourceLabel"),
	ScaleInCooldown: cdk.Duration_Minutes(jsii.Number(30)),
	ScaleOutCooldown: cdk.Duration_*Minutes(jsii.Number(30)),
})
```

## Initializer

TypeScript:

```ts
new TargetTrackingScalingPolicy(scope: Construct, id: string, props: TargetTrackingScalingPolicyProps)
```

Python:

```python
TargetTrackingScalingPolicy(scope: Construct, id: str, props: TargetTrackingScalingPolicyProps)
```

Java:

```java
new TargetTrackingScalingPolicy(Construct scope, String id, TargetTrackingScalingPolicyProps props)
```

C# / .NET:

```csharp
new TargetTrackingScalingPolicy(Construct scope, string id, TargetTrackingScalingPolicyProps props)
```

Golang:

```go
NewTargetTrackingScalingPolicy(Scope Construct, Id *string, Props TargetTrackingScalingPolicyProps)
```

## Construct Props

- `customMetric`: [IMetric](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.IMetric.html) — A custom metric for application autoscaling.

  **Default:** No custom metric.

  The metric must track utilization. Scaling out will happen if the metric is higher than
  the target value, scaling in will happen in the metric is lower than the target value.

  The metric must be in the same account and region as the scaling policy.

  Exactly one of customMetric or predefinedMetric must be specified.

- `disableScaleIn`: boolean = false — Indicates whether scale in by the target tracking policy is disabled.

  If the value is true, scale in is disabled and the target tracking policy
  won't remove capacity from the scalable resource. Otherwise, scale in is
  enabled and the target tracking policy can remove capacity from the
  scalable resource.

- `policyName`: string — A name for the scaling policy.

  **Default:** Automatically generated name.

- `predefinedMetric`: [PredefinedMetric](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_applicationautoscaling.PredefinedMetric.html) — A predefined metric for application autoscaling.

  **Default:** No predefined metrics.

  The metric must track utilization. Scaling out will happen if the metric is higher than
  the target value, scaling in will happen in the metric is lower than the target value.

  Exactly one of customMetric or predefinedMetric must be specified.

- `resourceLabel`: string — Identify the resource associated with the metric type.

  **Default:** No resource label.

  Only used for predefined metric ALBRequestCountPerTarget.

  Example value: `app/<load-balancer-name>/<load-balancer-id>/targetgroup/<target-group-name>/<target-group-id>`

- `scaleInCooldown`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Period after a scale in activity completes before another scale in activity can start.

  **Default:** Duration.seconds(300) for the following scalable targets: ECS services, Spot Fleet requests, EMR clusters, AppStream 2.0 fleets, Aurora DB clusters, Amazon SageMaker endpoint variants, Custom resources. For all other scalable targets, the default value is Duration.seconds(0): DynamoDB tables, DynamoDB global secondary indexes, Amazon Comprehend document classification endpoints, Lambda provisioned concurrency

- `scaleOutCooldown`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Period after a scale out activity completes before another scale out activity can start.

  **Default:** Duration.seconds(300) for the following scalable targets: ECS services, Spot Fleet requests, EMR clusters, AppStream 2.0 fleets, Aurora DB clusters, Amazon SageMaker endpoint variants, Custom resources. For all other scalable targets, the default value is Duration.seconds(0): DynamoDB tables, DynamoDB global secondary indexes, Amazon Comprehend document classification endpoints, Lambda provisioned concurrency

- `scalingTarget`: [IScalableTargetRef](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_applicationautoscaling.IScalableTargetRef.html) (required)

- `targetValue`: number (required) — The target value for the metric.

## Properties

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

- `scalingPolicyArn`: string — ARN of the scaling policy.

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

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