Skip to content
v2.274.0

ScalableTarget L2 construct ​

Define a scalable target.

Example ​

ts
const shardsScalableTarget = new appscaling.ScalableTarget(this, 'ElastiCacheRedisShardsScalableTarget', {
  serviceNamespace: appscaling.ServiceNamespace.ELASTICACHE,
  scalableDimension: 'elasticache:replication-group:NodeGroups',
  minCapacity: 2,
  maxCapacity: 10,
  resourceId: 'replication-group/main-cluster',
});

shardsScalableTarget.scaleToTrackMetric('ElastiCacheRedisShardsCPUUtilization', {
  targetValue: 20,
  predefinedMetric: appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
});
python
shards_scalable_target = appscaling.ScalableTarget(self, "ElastiCacheRedisShardsScalableTarget",
    service_namespace=appscaling.ServiceNamespace.ELASTICACHE,
    scalable_dimension="elasticache:replication-group:NodeGroups",
    min_capacity=2,
    max_capacity=10,
    resource_id="replication-group/main-cluster"
)

shards_scalable_target.scale_to_track_metric("ElastiCacheRedisShardsCPUUtilization",
    target_value=20,
    predefined_metric=appscaling.PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
)
java
ScalableTarget shardsScalableTarget = ScalableTarget.Builder.create(this, "ElastiCacheRedisShardsScalableTarget")
        .serviceNamespace(ServiceNamespace.ELASTICACHE)
        .scalableDimension("elasticache:replication-group:NodeGroups")
        .minCapacity(2)
        .maxCapacity(10)
        .resourceId("replication-group/main-cluster")
        .build();

shardsScalableTarget.scaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", BasicTargetTrackingScalingPolicyProps.builder()
        .targetValue(20)
        .predefinedMetric(PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
var shardsScalableTarget = new ScalableTarget(this, "ElastiCacheRedisShardsScalableTarget", new ScalableTargetProps {
    ServiceNamespace = ServiceNamespace.ELASTICACHE,
    ScalableDimension = "elasticache:replication-group:NodeGroups",
    MinCapacity = 2,
    MaxCapacity = 10,
    ResourceId = "replication-group/main-cluster"
});

shardsScalableTarget.ScaleToTrackMetric("ElastiCacheRedisShardsCPUUtilization", new BasicTargetTrackingScalingPolicyProps {
    TargetValue = 20,
    PredefinedMetric = PredefinedMetric.ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
shardsScalableTarget := appscaling.NewScalableTarget(this, jsii.String("ElastiCacheRedisShardsScalableTarget"), &ScalableTargetProps{
	ServiceNamespace: appscaling.ServiceNamespace_ELASTICACHE,
	ScalableDimension: jsii.String("elasticache:replication-group:NodeGroups"),
	MinCapacity: jsii.Number(2),
	MaxCapacity: jsii.Number(10),
	ResourceId: jsii.String("replication-group/main-cluster"),
})

shardsScalableTarget.ScaleToTrackMetric(jsii.String("ElastiCacheRedisShardsCPUUtilization"), &BasicTargetTrackingScalingPolicyProps{
	TargetValue: jsii.Number(20),
	PredefinedMetric: appscaling.PredefinedMetric_ELASTICACHE_PRIMARY_ENGINE_CPU_UTILIZATION,
})

Initializer ​

ts
new ScalableTarget(scope: Construct, id: string, props: ScalableTargetProps)
python
ScalableTarget(scope: Construct, id: str, props: ScalableTargetProps)
java
new ScalableTarget(Construct scope, String id, ScalableTargetProps props)
csharp
new ScalableTarget(Construct scope, string id, ScalableTargetProps props)
go
NewScalableTarget(Scope Construct, Id *string, Props ScalableTargetProps)

Construct Props ​

maxCapacitynumbermax_capacityint | floatmaxCapacityNumberMaxCapacitydoubleMaxCapacity*float64required#
The maximum value that Application Auto Scaling can use to scale a target during a scaling activity.
minCapacitynumbermin_capacityint | floatminCapacityNumberMinCapacitydoubleMinCapacity*float64required#
The minimum value that Application Auto Scaling can use to scale a target during a scaling activity.
resourceIdstringresource_idstrresourceIdStringResourceIdstringResourceId*stringrequired#
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

roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRole= A role is automatically created#
Role that allows Application Auto Scaling to modify your scalable target.
scalableDimensionstringscalable_dimensionstrscalableDimensionStringScalableDimensionstringScalableDimension*stringrequired#
The scalable dimension that's associated with the scalable target.

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

Example value: ecs:service:DesiredCount

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

Properties ​

The environment this resource belongs to.
notes

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.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRolerequired#
The role used to give AutoScaling permissions to your resource.
scalableTargetIdstringscalable_target_idstrscalableTargetIdStringScalableTargetIdstringScalableTargetId*stringrequired#
ID of the Scalable Target.

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

scalableTargetRefScalableTargetReferencescalable_target_refScalableTargetReferencescalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferencerequired#
A reference to a ScalableTarget resource.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.

Methods ​

addToRolePolicy(statement: PolicyStatement): voiddef add_to_role_policy(self, statement: PolicyStatement) -> Nonepublic void addToRolePolicy(PolicyStatement statement)public void AddToRolePolicy(PolicyStatement statement)func AddToRolePolicy(Statement PolicyStatement)#
Add a policy statement to the role's policy.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

When set, any cross-stack reference to this resource will use the specified mechanism instead of the global default determined by the @aws-cdk/core:defaultCrossStackReferences context key. This is useful for selectively weakening specific references to avoid the "deadly embrace" problem without changing the app-wide default.

Parameters

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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

fromScalableTargetAttributes(scope: Construct, id: string, attrs: ScalableTargetAttributes): IScalableTarget@staticmethod def from_scalable_target_attributes(scope: Construct, id: str, attrs: ScalableTargetAttributes) -> IScalableTargetpublic static IScalableTarget fromScalableTargetAttributes(Construct scope, String id, ScalableTargetAttributes attrs)public static IScalableTarget FromScalableTargetAttributes(Construct scope, string id, ScalableTargetAttributes attrs)func FromScalableTargetAttributes(Scope Construct, Id *string, Attrs ScalableTargetAttributes) IScalableTargetstatic#
Create a referenceable `IScalableTarget` object based on properties of a resource that already exists in your account.
fromScalableTargetId(scope: Construct, id: string, scalableTargetId: string): IScalableTarget@staticmethod def from_scalable_target_id(scope: Construct, id: str, scalable_target_id: str) -> IScalableTargetpublic static IScalableTarget fromScalableTargetId(Construct scope, String id, String scalableTargetId)public static IScalableTarget FromScalableTargetId(Construct scope, string id, string scalableTargetId)func FromScalableTargetId(Scope Construct, Id *string, ScalableTargetId *string) IScalableTargetstatic#
Create a referenceable `IScalableTarget` object based on properties of a resource that already exists in your account.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
scaleOnMetric(id: string, props: BasicStepScalingPolicyProps): StepScalingPolicydef scale_on_metric(self, id: str, props: BasicStepScalingPolicyProps) -> StepScalingPolicypublic StepScalingPolicy scaleOnMetric(String id, BasicStepScalingPolicyProps props)public StepScalingPolicy ScaleOnMetric(string id, BasicStepScalingPolicyProps props)func ScaleOnMetric(Id *string, Props BasicStepScalingPolicyProps) StepScalingPolicy#
Scale out or in, in response to a metric.
scaleOnSchedule(id: string, action: ScalingSchedule): voiddef scale_on_schedule(self, id: str, action: ScalingSchedule) -> Nonepublic void scaleOnSchedule(String id, ScalingSchedule action)public void ScaleOnSchedule(string id, ScalingSchedule action)func ScaleOnSchedule(Id *string, Action ScalingSchedule)#
Scale out or in based on time.
scaleToTrackMetric(id: string, props: BasicTargetTrackingScalingPolicyProps): TargetTrackingScalingPolicydef scale_to_track_metric(self, id: str, props: BasicTargetTrackingScalingPolicyProps) -> TargetTrackingScalingPolicypublic TargetTrackingScalingPolicy scaleToTrackMetric(String id, BasicTargetTrackingScalingPolicyProps props)public TargetTrackingScalingPolicy ScaleToTrackMetric(string id, BasicTargetTrackingScalingPolicyProps props)func ScaleToTrackMetric(Id *string, Props BasicTargetTrackingScalingPolicyProps) TargetTrackingScalingPolicy#
Scale out or in in order to keep a metric around a target value.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.