aws-cdk-lib.aws_applicationautoscaling.ScalableTarget

class ScalableTarget (construct)

LanguageType name
.NETAmazon.CDK.AWS.ApplicationAutoScaling.ScalableTarget
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsapplicationautoscaling#ScalableTarget
Javasoftware.amazon.awscdk.services.applicationautoscaling.ScalableTarget
Pythonaws_cdk.aws_applicationautoscaling.ScalableTarget
TypeScript (source)aws-cdk-lib » aws_applicationautoscaling » ScalableTarget

Implements IConstruct, IDependable, IResource, IScalableTarget

Define a scalable target.

Example

import * as lambda from 'aws-cdk-lib/aws-lambda';

declare const code: lambda.Code;

const handler = new lambda.Function(this, 'MyFunction', {
  runtime: lambda.Runtime.PYTHON_3_7,
  handler: 'index.handler',
  code,

  reservedConcurrentExecutions: 2,
});

const fnVer = handler.currentVersion;

const target = new appscaling.ScalableTarget(this, 'ScalableTarget', {
  serviceNamespace: appscaling.ServiceNamespace.LAMBDA,
  maxCapacity: 100,
  minCapacity: 10,
  resourceId: `function:${handler.functionName}:${fnVer.version}`,
  scalableDimension: 'lambda:function:ProvisionedConcurrency',
})

target.scaleToTrackMetric('PceTracking', {
  targetValue: 0.9,
  predefinedMetric: appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION,
})

Initializer

new ScalableTarget(scope: Construct, id: string, props: ScalableTargetProps)

Parameters

  • scope Construct
  • id string
  • props ScalableTargetProps

Construct Props

NameTypeDescription
maxCapacitynumberThe maximum value that Application Auto Scaling can use to scale a target during a scaling activity.
minCapacitynumberThe minimum value that Application Auto Scaling can use to scale a target during a scaling activity.
resourceIdstringThe resource identifier to associate with this scalable target.
scalableDimensionstringThe scalable dimension that's associated with the scalable target.
serviceNamespaceServiceNamespaceThe namespace of the AWS service that provides the resource or custom-resource for a resource provided by your own application or service.
role?IRoleRole that allows Application Auto Scaling to modify your scalable target.

maxCapacity

Type: number

The maximum value that Application Auto Scaling can use to scale a target during a scaling activity.


minCapacity

Type: number

The minimum value that Application Auto Scaling can use to scale a target during a scaling activity.


resourceId

Type: string

The resource identifier to associate with this scalable target.

This string consists of the resource type and unique identifier.

Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH

See also: https://docs.aws.amazon.com/autoscaling/application/APIReference/API_RegisterScalableTarget.html


scalableDimension

Type: string

The scalable dimension that's associated with the scalable target.

Specify the service namespace, resource type, and scaling property.

Example value: ecs:service:DesiredCount

See also: https://docs.aws.amazon.com/autoscaling/application/APIReference/API_ScalingPolicy.html


serviceNamespace

Type: ServiceNamespace

The namespace of the AWS service that provides the resource or custom-resource for a resource provided by your own application or service.

For valid AWS service namespace values, see the RegisterScalableTarget action in the Application Auto Scaling API Reference.

See also: https://docs.aws.amazon.com/autoscaling/application/APIReference/API_RegisterScalableTarget.html


role?

Type: IRole (optional, default: A role is automatically created)

Role that allows Application Auto Scaling to modify your scalable target.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
roleIRoleThe role used to give AutoScaling permissions to your resource.
scalableTargetIdstringID of the Scalable Target.
stackStackThe stack in which this resource is defined.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


role

Type: IRole

The role used to give AutoScaling permissions to your resource.


scalableTargetId

Type: string

ID of the Scalable Target.

Example value: service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs


stack

Type: Stack

The stack in which this resource is defined.

Methods

NameDescription
addToRolePolicy(statement)Add a policy statement to the role's policy.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
scaleOnMetric(id, props)Scale out or in, in response to a metric.
scaleOnSchedule(id, action)Scale out or in based on time.
scaleToTrackMetric(id, props)Scale out or in in order to keep a metric around a target value.
toString()Returns a string representation of this construct.
static fromScalableTargetId(scope, id, scalableTargetId)

addToRolePolicy(statement)

public addToRolePolicy(statement: PolicyStatement): void

Parameters

  • statement PolicyStatement

Add a policy statement to the role's policy.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


scaleOnMetric(id, props)

public scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): StepScalingPolicy

Parameters

  • id string
  • props BasicStepScalingPolicyProps

Returns

  • StepScalingPolicy

Scale out or in, in response to a metric.


scaleOnSchedule(id, action)

public scaleOnSchedule(id: string, action: ScalingSchedule): void

Parameters

  • id string
  • action ScalingSchedule

Scale out or in based on time.


scaleToTrackMetric(id, props)

public scaleToTrackMetric(id: string, props: BasicTargetTrackingScalingPolicyProps): TargetTrackingScalingPolicy

Parameters

  • id string
  • props BasicTargetTrackingScalingPolicyProps

Returns

  • TargetTrackingScalingPolicy

Scale out or in in order to keep a metric around a target value.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromScalableTargetId(scope, id, scalableTargetId)

public static fromScalableTargetId(scope: Construct, id: string, scalableTargetId: string): IScalableTarget

Parameters

  • scope Construct
  • id string
  • scalableTargetId string

Returns

  • IScalableTarget