ScalableTarget
- class aws_cdk.aws_applicationautoscaling.ScalableTarget(scope, id, *, max_capacity, min_capacity, resource_id, scalable_dimension, service_namespace, role=None)
Bases:
Resource
Define a scalable target.
- ExampleMetadata:
infused
Example:
import aws_cdk.aws_lambda as lambda_ # code: lambda.Code handler = lambda_.Function(self, "MyFunction", runtime=lambda_.Runtime.PYTHON_3_7, handler="index.handler", code=code, reserved_concurrent_executions=2 ) fn_ver = handler.current_version target = appscaling.ScalableTarget(self, "ScalableTarget", service_namespace=appscaling.ServiceNamespace.LAMBDA, max_capacity=100, min_capacity=10, resource_id=f"function:{handler.functionName}:{fnVer.version}", scalable_dimension="lambda:function:ProvisionedConcurrency" ) target.scale_to_track_metric("PceTracking", target_value=0.9, predefined_metric=appscaling.PredefinedMetric.LAMBDA_PROVISIONED_CONCURRENCY_UTILIZATION )
- Parameters:
scope (
Construct
) –id (
str
) –max_capacity (
Union
[int
,float
]) – The maximum value that Application Auto Scaling can use to scale a target during a scaling activity.min_capacity (
Union
[int
,float
]) – The minimum value that Application Auto Scaling can use to scale a target during a scaling activity.resource_id (
str
) – 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
scalable_dimension (
str
) – The scalable dimension that’s associated with the scalable target. Specify the service namespace, resource type, and scaling property. Example value:ecs:service:DesiredCount
service_namespace (
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.role (
Optional
[IRole
]) – Role that allows Application Auto Scaling to modify your scalable target. Default: A role is automatically created
Methods
- add_to_role_policy(statement)
Add a policy statement to the role’s policy.
- Parameters:
statement (
PolicyStatement
) –- Return type:
None
- apply_removal_policy(policy)
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
).- Parameters:
policy (
RemovalPolicy
) –- Return type:
None
- scale_on_metric(id, *, metric, scaling_steps, adjustment_type=None, cooldown=None, datapoints_to_alarm=None, evaluation_periods=None, metric_aggregation_type=None, min_adjustment_magnitude=None)
Scale out or in, in response to a metric.
- Parameters:
id (
str
) –metric (
IMetric
) – Metric to scale on.scaling_steps (
Sequence
[Union
[ScalingInterval
,Dict
[str
,Any
]]]) – The intervals for scaling. Maps a range of metric values to a particular scaling behavior. Must be between 2 and 40 steps.adjustment_type (
Optional
[AdjustmentType
]) – How the adjustment numbers inside ‘intervals’ are interpreted. Default: ChangeInCapacitycooldown (
Optional
[Duration
]) – Grace period after scaling activity. Subsequent scale outs during the cooldown period are squashed so that only the biggest scale out happens. Subsequent scale ins during the cooldown period are ignored. Default: No cooldown perioddatapoints_to_alarm (
Union
[int
,float
,None
]) – The number of data points out of the evaluation periods that must be breaching to trigger a scaling action. Creates an “M out of N” alarm, where this property is the M and the value set forevaluationPeriods
is the N value. Only has meaning ifevaluationPeriods != 1
. Default:evaluationPeriods
evaluation_periods (
Union
[int
,float
,None
]) – How many evaluation periods of the metric to wait before triggering a scaling action. Raising this value can be used to smooth out the metric, at the expense of slower response times. IfdatapointsToAlarm
is not set, then all data points in the evaluation period must meet the criteria to trigger a scaling action. Default: 1metric_aggregation_type (
Optional
[MetricAggregationType
]) – Aggregation to apply to all data points over the evaluation periods. Only has meaning ifevaluationPeriods != 1
. Default: - The statistic from the metric if applicable (MIN, MAX, AVERAGE), otherwise AVERAGE.min_adjustment_magnitude (
Union
[int
,float
,None
]) – Minimum absolute number to adjust capacity with as result of percentage scaling. Only when using AdjustmentType = PercentChangeInCapacity, this number controls the minimum absolute effect size. Default: No minimum scaling effect
- Return type:
- scale_on_schedule(id, *, schedule, end_time=None, max_capacity=None, min_capacity=None, start_time=None)
Scale out or in based on time.
- Parameters:
id (
str
) –schedule (
Schedule
) – When to perform this action.end_time (
Optional
[datetime
]) – When this scheduled action expires. Default: The rule never expires.max_capacity (
Union
[int
,float
,None
]) – The new maximum capacity. During the scheduled time, the current capacity is above the maximum capacity, Application Auto Scaling scales in to the maximum capacity. At least one of maxCapacity and minCapacity must be supplied. Default: No new maximum capacitymin_capacity (
Union
[int
,float
,None
]) – The new minimum capacity. During the scheduled time, if the current capacity is below the minimum capacity, Application Auto Scaling scales out to the minimum capacity. At least one of maxCapacity and minCapacity must be supplied. Default: No new minimum capacitystart_time (
Optional
[datetime
]) – When this scheduled action becomes active. Default: The rule is activate immediately
- Return type:
None
- scale_to_track_metric(id, *, target_value, custom_metric=None, predefined_metric=None, resource_label=None, disable_scale_in=None, policy_name=None, scale_in_cooldown=None, scale_out_cooldown=None)
Scale out or in in order to keep a metric around a target value.
- Parameters:
id (
str
) –target_value (
Union
[int
,float
]) – The target value for the metric.custom_metric (
Optional
[IMetric
]) – A custom metric for application autoscaling. 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. Default: - No custom metric.predefined_metric (
Optional
[PredefinedMetric
]) – A predefined metric for application autoscaling. 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. Default: - No predefined metrics.resource_label (
Optional
[str
]) – Identify the resource associated with the metric type. Only used for predefined metric ALBRequestCountPerTarget. Example value:app/<load-balancer-name>/<load-balancer-id>/targetgroup/<target-group-name>/<target-group-id>
Default: - No resource label.disable_scale_in (
Optional
[bool
]) – 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. Default: falsepolicy_name (
Optional
[str
]) – A name for the scaling policy. Default: - Automatically generated name.scale_in_cooldown (
Optional
[Duration
]) – 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 concurrencyscale_out_cooldown (
Optional
[Duration
]) – 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
- Return type:
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- env
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
The tree node.
- role
The role used to give AutoScaling permissions to your resource.
- scalable_target_id
ID of the Scalable Target.
Example value:
service/ecsStack-MyECSCluster-AB12CDE3F4GH/ecsStack-MyECSService-AB12CDE3F4GH|ecs:service:DesiredCount|ecs
- Attribute:
true
- stack
The stack in which this resource is defined.
Static Methods
- classmethod from_scalable_target_id(scope, id, scalable_target_id)
- Parameters:
scope (
Construct
) –id (
str
) –scalable_target_id (
str
) –
- Return type:
- classmethod is_construct(x)
Checks if
x
is a construct.Use this method instead of
instanceof
to properly detectConstruct
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 classConstruct
in each copy of theconstructs
library is seen as a different class, and an instance of one class will not test asinstanceof
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 theconstructs
library can be accidentally installed, andinstanceof
will behave unpredictably. It is safest to avoid usinginstanceof
, and using this type-testing method instead.- Parameters:
x (
Any
) – Any object.- Return type:
bool
- Returns:
true if
x
is an object created from a class which extendsConstruct
.
- classmethod is_owned_resource(construct)
Returns true if the construct was created by CDK, and false otherwise.
- Parameters:
construct (
IConstruct
) –- Return type:
bool
- classmethod is_resource(construct)
Check whether the given construct is a Resource.
- Parameters:
construct (
IConstruct
) –- Return type:
bool