ScalableTaskCount
- class aws_cdk.aws_ecs.ScalableTaskCount(scope, id, *, dimension, resource_id, role, service_namespace, max_capacity, min_capacity=None)
Bases:
BaseScalableAttribute
The scalable attribute representing task count.
- ExampleMetadata:
infused
Example:
# cluster: ecs.Cluster load_balanced_fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "Service", cluster=cluster, memory_limit_mi_b=1024, desired_count=1, cpu=512, task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions( image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample") ) ) scalable_target = load_balanced_fargate_service.service.auto_scale_task_count( min_capacity=1, max_capacity=20 ) scalable_target.scale_on_cpu_utilization("CpuScaling", target_utilization_percent=50 ) scalable_target.scale_on_memory_utilization("MemoryScaling", target_utilization_percent=50 )
Constructs a new instance of the ScalableTaskCount class.
- Parameters:
scope (
Construct
) –id (
str
) –dimension (
str
) – Scalable dimension of the attribute.resource_id (
str
) – Resource ID of the attribute.role (
IRole
) – Role to use for scaling.service_namespace (
ServiceNamespace
) – Service namespace of the scalable attribute.max_capacity (
Union
[int
,float
]) – Maximum capacity to scale to.min_capacity (
Union
[int
,float
,None
]) – Minimum capacity to scale to. Default: 1
Methods
- scale_on_cpu_utilization(id, *, target_utilization_percent, disable_scale_in=None, policy_name=None, scale_in_cooldown=None, scale_out_cooldown=None)
Scales in or out to achieve a target CPU utilization.
- Parameters:
id (
str
) –target_utilization_percent (
Union
[int
,float
]) – The target value for CPU utilization across all tasks in the service.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:
None
- scale_on_memory_utilization(id, *, target_utilization_percent, disable_scale_in=None, policy_name=None, scale_in_cooldown=None, scale_out_cooldown=None)
Scales in or out to achieve a target memory utilization.
- Parameters:
id (
str
) –target_utilization_percent (
Union
[int
,float
]) – The target value for memory utilization across all tasks in the service.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:
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)
Scales in or out based on a specified metric value.
- 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: - Same asevaluationPeriods
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:
None
- scale_on_request_count(id, *, requests_per_target, target_group, disable_scale_in=None, policy_name=None, scale_in_cooldown=None, scale_out_cooldown=None)
Scales in or out to achieve a target Application Load Balancer request count per target.
- Parameters:
id (
str
) –requests_per_target (
Union
[int
,float
]) – The number of ALB requests per target.target_group (
ApplicationTargetGroup
) – The ALB target group name.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:
None
- scale_on_schedule(id, *, schedule, end_time=None, max_capacity=None, min_capacity=None, start_time=None, time_zone=None)
Scales in or out based on a specified scheduled 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 immediatelytime_zone (
Optional
[TimeZone
]) – The time zone used when referring to the date and time of a scheduled action, when the scheduled action uses an at or cron expression. Default: - UTC
- Return type:
None
- scale_to_track_custom_metric(id, *, metric, target_value, disable_scale_in=None, policy_name=None, scale_in_cooldown=None, scale_out_cooldown=None)
Scales in or out to achieve a target on a custom metric.
- Parameters:
id (
str
) –metric (
IMetric
) – The custom CloudWatch metric to track. The metric must represent utilization; that is, you will always get the following behavior: - metric > targetValue => scale out - metric < targetValue => scale intarget_value (
Union
[int
,float
]) – The target value for the custom CloudWatch metric.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:
None
- to_string()
Returns a string representation of this construct.
- Return type:
str
Attributes
- node
The tree node.
Static Methods
- 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
.