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?
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.
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.
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.
Yes, you can configure more than one load balancer with an autoscaling group.
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.
######## 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With