Yash
Yash

Reputation: 699

AWS EC2 Target Tracking Scaling Policies - Scaling multiple instances

I am exploring AWS EC2 autoscaling with target tracking and custom metrics. From the documents I understand that when a particular target is hit, an autoscale event is triggered that either scales in or out the EC2 instance.

I followed the instructions as provided by the terraform docs for aws_autoscaling_policy and is working, but this is scaling in and out just one instance.

Now, for my use-case, i want to scale in and out two instances. Is there a way to do this with target tracking scaling policy?

Any help, much appreciated.

Following is a working policy written in terraform for target tracking with custom metrics.

resource "aws_autoscaling_policy" "target-tracking-autoscale" {

name = "target-traclking-policy"

autoscaling_group_name = "target-tracking-asg"
policy_type            = "TargetTrackingScaling"

target_tracking_configuration {
    customized_metric_specification {
        metric_dimension {
            name  = "asg"
            value = "custom-value"
        }

        metric_name = "CUSTOM_METRIC"
        namespace   = "CUSTOM-METRIC/NAMESPACE"
        statistic   = "Average"
        }
        target_value = "2"
    }
}

Regards.


Update 1

I have tried adding the step_adjustment but this parameter is exclusively for step scaling. Terraform throws this following error:

Error: Error applying plan:

1 error(s) occurred:

* module.pt-wowza.aws_autoscaling_policy.target-tracking-autoscale: 1 error(s) occurred:

* aws_autoscaling_policy.target-tracking-autoscale: step_adjustment is only supported for policy type StepScaling

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

Upvotes: 0

Views: 2637

Answers (1)

shashank-chintala
shashank-chintala

Reputation: 1

I ran into the same problem and was able to fix it by adding policy_type attribute to the scaling policy resource

policy_type = "TargetTrackingScaling"
policy_type - (Optional) The policy type, either "SimpleScaling", "StepScaling", "TargetTrackingScaling", or "PredictiveScaling". If this value isn't provided, AWS will default to "SimpleScaling."

Upvotes: 0

Related Questions