-
For context, I'm trying to create a cloudwatch alarm that scales down an ecs task. This is the cdk snippet alarm = cloudwatch.Alarm(
self,
id="alarm",
metric=ecs_service.target_group.metric_healthy_host_count(),
comparison_operator=cloudwatch.ComparisonOperator.LESS_THAN_OR_EQUAL_TO_THRESHOLD,
threshold=0, # Trigger the alarm when there are no healthy hosts
evaluation_periods=1,
treat_missing_data=cloudwatch.TreatMissingData.NOT_BREACHING,
)
# Scale down to 0 tasks when the alarm is triggered
scalable_target = applicationautoscaling.ScalableTarget(
self,
id="<>_scalable_target",
service_namespace=applicationautoscaling.ServiceNamespace.ECS,
resource_id=f"service/{cluster.cluster_name}/{ecs_service.service.service_name}",
scalable_dimension="ecs:service:DesiredCount",
min_capacity=0,
max_capacity=1
)
step_scaling_action = applicationautoscaling.StepScalingAction(
self,
id="<>_scale_down_action",
scaling_target=scalable_target,
adjustment_type=applicationautoscaling.AdjustmentType.CHANGE_IN_CAPACITY,
)
step_scaling_action.add_adjustment(
lower_bound=0,
upper_bound=1,
adjustment=-1,
)
alarm.add_alarm_action(step_scaling_action) When doing
Does anyone have any insight into why this is failing? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Resolved, the fix here was to first cast the step scaling action to an Because I was using |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Resolved, the fix here was to first cast the step scaling action to an
AutoScalingAction
likeauto_scaling_action = cloudwatch_actions.AutoScalingAction(step_scaling_action)
.Because I was using
ApplicationLoadBalancedFargateService
it also seems like the more idiomatic way of creating an autoscaling action is to create aScalableTarget
fromauto_scale_task_count
and then useScalableTarget.scale_on_metric
.