3

I have created an autoscaling target and a policy which is attached to it.

AutoScalingPolicy:
    Type: AWS::ApplicationAutoScaling::ScalingPolicy
    Properties:
      PolicyName: !Join ['', [!Ref ServiceName, auto-scaling-policy]]
      PolicyType: TargetTrackingScaling
      ScalingTargetId: !Ref AutoScalingTarget
      TargetTrackingScalingPolicyConfiguration:
        PredefinedMetricSpecification:
          PredefinedMetricType: ECSServiceAverageCPUUtilization
        ScaleInCooldown: 10
        ScaleOutCooldown: 10
        # Keep things at or lower than 50% CPU utilization, for example
        TargetValue: !Ref AutoScalingTargetValue

This is creating cloudwatch alarms as:

High: 3 datapoints within 3 minutes

Low: 15 datapoints within 15 minutes

I want to customize this to:

High: 1 datapoint within 1 minute

Low: 1 datapoint within 1 minute

I am able to do this manually from AWS console. However, struggling to find a way to do the same using cloudformation template.

kk.
  • 3,747
  • 12
  • 36
  • 67

2 Answers2

2

Target tracking does not actually have a "high" and "low" threshold. With target tracking you set the target CPU utilization percent value you want to try to keep it at, and autoscaling automatically updates the number tasks up and down to try to keep the CPU utilization at that value.

If you want to have more fine grained control, you'd need to use a "step scaling policy". This allows you to set specific values like "if CPU percent is between 0 and 10% over my target of 50% then increase by 1", and "if CPU percent is between 10% and 20% over my target of 50% then increase by 2".

You can see an example of such a step scaling policy, in a downloadable open source CloudFormation template here: https://containersonaws.com/architecture/autoscaling-service-containers/ It is too to long include directly in this answer, but you can use these official AWS sample templates as a starting point for your step scaling policy.

nathanpeck
  • 4,608
  • 1
  • 20
  • 18
0

While target tracking allows you to specify a single value, under the covers that turns into two alarms in CloudWatch. The High alarm will be YourMetric > YourTargetValue for X datapoints for Y minutes. The Low alarm will be YourMetric < SomeValue for A datapoints for B minutes.

bruce szalwinski
  • 724
  • 1
  • 8
  • 27
  • 3
    Is there a way to make it so the Low alarms don't look so... alarming? It basically looks like my environment is always in fault... reminds me of Homer Simpson's "Everything is okay alarm." – nitsujri Jul 31 '20 at 05:33
  • @nitsujri Did you figure this out or is it something we have to accept? – Chad Greenburg Dec 18 '21 at 17:39
  • Downvoted because `SomeValue` is actually 90% of `YourTargetValue`. The target tracking policy will increase capacity once value > `YourTargetValue` immediately, but it won't remove capacity when value < `YourTargetValue`, until the value is lower than 10% of the `YourTargetValue`. See the "Supporting application availability during high utilization periods" in https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking.html – v.ng Dec 08 '22 at 04:10