Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add multiple auto-scaling policy with Elastic Beanstlak

We have automated our deployment life-cyle with ElasticBeanstalk and we are happy it except one thing; we want to have multiple auto-scaling policy like CPU Usage and network traffic but it seems we just have to choose one of the metrics.

We are currently using open source tool named eb_deployer and it supports configuration listed in following link:http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-general.html#command-options-general-autoscalingtrigger

As far as we understood, we can only set one policy with aws:autoscaling:trigger

We also look for .ebextensions but it seems .ebextension also same limitations on that matter. So, we were wondering is there any way to use multiple auto-scaling policy with ElasticBeanstalk?

like image 994
endertunc Avatar asked Oct 28 '16 13:10

endertunc


People also ask

How many types of scaling policies can be configured for Auto Scaling?

To help ensure that the application performs at optimum levels, there are two policies that control when the Auto Scaling group should scale out. One is a target tracking policy that uses a custom metric to add and remove capacity based on the number of SQS messages in the queue.

Does Elastic Beanstalk automatically scale?

Your AWS Elastic Beanstalk environment includes an Auto Scaling group that manages the Amazon EC2 instances in your environment. In a single-instance environment, the Auto Scaling group ensures that there is always one instance running.

Can an Auto Scaling group have multiple instance types?

ECS and EKS – If you are running Amazon Elastic Container Service (Amazon ECS) or Amazon Elastic Kubernetes Service (EKS) on a cluster that makes use of an Auto Scaling Group, you can update the group to make use of multiple instance types and purchase options.

Can you configure multiple load balancers with a single Auto Scaling group?

Yes, you can configure more than one load balancer with an autoscaling group.


1 Answers

The following configuration works for me and should be placed in the elastic bean extensions config files: This configuration does several things that change the default behavior:

  • It disables the auto generated alarms

  • It create 2 scale policies: one CPU load , the other on number of requests per target.

  • Per alarm it is using a different evaluation period for scale up versus scale down, since I wish to scale up fast but scale down slow.

disabling the auto generated alarms:

 ######## disable the default alarms ##############
  AWSEBCloudwatchAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions: []

  AWSEBCloudwatchAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions: []
  
  
  #############   create custom policies ##################
  AutoScalingCustomScaleDownPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment: -1

  AutoScalingCustomScaleUpPolicy:
    Type: AWS::AutoScaling::ScalingPolicy
    Properties:
      AdjustmentType: ChangeInCapacity
      AutoScalingGroupName: {Ref: AWSEBAutoScalingGroup}
      ScalingAdjustment: 1
 
 
 
 ############## alarms for cpu load - reusing the default policy of EB #######
   CustomScalingAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AWSEBAutoScalingScaleUpPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale up on cpu load" ]]}
      ComparisonOperator: GreaterThanThreshold
      Dimensions:
        - Name: AutoScalingGroupName
          Value: {Ref: AWSEBAutoScalingGroup}
      Statistic: Average
      Period: 60
      EvaluationPeriods: 2
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Threshold: 55

  CustomScalingAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AWSEBAutoScalingScaleDownPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale down on cpu load" ]]}
      ComparisonOperator: LessThanThreshold
      Dimensions:
        - Name: AutoScalingGroupName
          Value: {Ref: AWSEBAutoScalingGroup}
      Period: 60
      Statistic: Average
      EvaluationPeriods: 15
      MetricName: CPUUtilization
      Namespace: AWS/EC2
      Threshold: 20



 ############# alarms on request count per target ####################
 ############# using the new custom policy        ####################
  CustomScalingOnRequestCountAlarmLow:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AutoScalingCustomScaleDownPolicy}
      InsufficientDataActions:
        - {Ref: AWSEBAutoScalingScaleDownPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale down on request count." ]]}
      ComparisonOperator: LessThanThreshold
      Dimensions:
        - Name: LoadBalancer
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancer", "LoadBalancerFullName" ] }
        - Name: TargetGroup
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancerTargetGroup", "TargetGroupFullName" ] }
      Period: 60
      Statistic: Sum
      EvaluationPeriods: 5
      MetricName: RequestCountPerTarget
      Namespace: AWS/ApplicationELB
      Threshold: 70

  CustomScalingOnRequestCountAlarmHigh:
    Type: AWS::CloudWatch::Alarm
    Properties:
      AlarmActions:
        - {Ref: AutoScalingCustomScaleUpPolicy}
      AlarmDescription: { "Fn::Join" : ["", [{ "Ref" : "AWSEBEnvironmentName" }, ": scale up on request count." ]]}
      ComparisonOperator: GreaterThanThreshold
      Dimensions:
        - Name: LoadBalancer
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancer", "LoadBalancerFullName" ] }
        - Name: TargetGroup
          Value: { "Fn::GetAtt": [ "AWSEBV2LoadBalancerTargetGroup", "TargetGroupFullName" ] }
      Period: 60
      Statistic: Sum
      EvaluationPeriods: 2
      MetricName: RequestCountPerTarget
      Namespace: AWS/ApplicationELB
      Threshold: 250
like image 125
Tamar Inbar Avatar answered Oct 18 '22 03:10

Tamar Inbar