By default, AWS ElasticBeanstalk scales on NetworkOut
However, I am wanting to scale on two scenarios, network out and CPU utilization.
Is there a way to do this so that if either of these exceeds their limit, it will scale?
In ElasticBeanstalk console Configuration > Scaling > Scaling Trigger you can only set one Trigger Measurement like CPUUtilization or NetworkIn or NetworkOut or other options present.
If you need multiple scaling policies, you can add them manually or through ebextensions config file to ElasticBeanstalk's Auto Scaling group like described here. Add a Simple Scaling policy or Target Tracking Scaling policy.
Add below to ebextension config file to create a Target tracking scaling policy:
Resources:
POL:
Type: 'AWS::AutoScaling::ScalingPolicy'
Properties:
AutoScalingGroupName: !Ref AWSEBAutoScalingGroup
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 80
To create a Simple scaling policy, you should create a scaling policy and CloudWatch resource like here
Related
I created a Capacity Provider.
Then, I deployed a Service with that Capacity Provider and with binpack (CPU) strategy.
Service:
Type: AWS::ECS::Service
Properties:
ServiceName: my-service
TaskDefinition: my-td
Cluster: my-cluster
CapacityProviderStrategy:
- CapacityProvider: my-capacity-provider
Weight: 1
PlacementStrategies:
- Type: binpack
Field: cpu
DesiredCount: 1
This also creates the alarms in CW for high and low CPU usage.
When I add 15 tasks, after a while, the high alarm goes on and new EC2 instances are added.
Then, if I update the number of tasks to 6... Nothing happens. The low usage alarm is never triggered and the EC2 instances are not removed.
However, the service deregisters the extra tasks but the required 6 and enters to steady state.
Does anyone have this issue?
What can I do?
I know I could go to ECS Cluster, then in the ECS instances tab select the extra EC2 instances and drain them. However, this manual action would kill the purpose o using CloudFormation.
I'm trying to create a new Capacity Provider
I deployed the following CloudFormation snippet:
myECSCapacityProvider:
Type: AWS::ECS::CapacityProvider
Properties:
Name: my-project-asg-cp
AutoScalingGroupProvider:
AutoScalingGroupArn: !Ref myAutoScalingGroup
ManagedScaling:
MaximumScalingStepSize: 10
MinimumScalingStepSize: 1
Status: ENABLED
TargetCapacity: 100
ManagedTerminationProtection: DISABLED
I have the resource ASG (myAutoScalingGroup) created.
When I go to the ECS console and then to the Capacity Providers tab it is blank, no CPs are listed.
If I try to create the same CP through the console, using the name my-project-asg-cp I see the following error:
There was an error creating the capacity provider.
Fix the following error and try again.
The specified Auto Scaling group ARN is already being used by another capacity provider.
Specify a unique Auto Scaling group ARN and try again.
So it seems somehow the CP was created but it is not listed.
And of course, I don't have any error in CloudFormation.
If I check the resources tab I can see the resource created:
myECSCapacityProvider my-project-asg-cp AWS::ECS::CapacityProvider CREATE_COMPLETE
Also, the cli doesn't show it either.
Does anyone has faced this error?
Associate the capacity provided with the cluster:
ECSCluster:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: <your-ecs-cluster>
CapacityProviders:
- !Ref myECSCapacityProvider
I have added a Capacity Provider to an ECS cluster. While scale-out events work as expected due to changes in CapacityProviderReservation metric, scale-in events do not work.
In my case, the TargetCapacity property is set to 90, but looking at CloudWatch the average for the CapacityProviderReservation metric currently sits at 50%. This has been the case for the last 16 hours.
According to AWS's own documentation, scale-in events occur -
When using dynamic scaling policies and the size of the group decreases as a result of changes in a metric's value
So it seems like the Capacity Provider is not changing the desired size of the ASG as expected.
Am I missing something here, or do capacity providers tied to ASG's simply not work both ways?
ASG and Capacity Provider resources in CloudFormation
Resources:
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
AutoScalingGroupName: !Sub ${ResourceNamePrefix}-asg
VPCZoneIdentifier:
- !Ref PrivateSubnetAId
LaunchTemplate:
LaunchTemplateId: !Ref Ec2LaunchTemplate
Version: !GetAtt Ec2LaunchTemplate.LatestVersionNumber
MinSize: 0
MaxSize: 3
DesiredCapacity: 1
EcsCapacityProvider:
Type: AWS::ECS::CapacityProvider
Properties:
Name: !Sub ${ResourceNamePrefix}-ecs-capacity-provider
AutoScalingGroupProvider:
AutoScalingGroupArn: !Ref AutoScalingGroup
ManagedScaling:
Status: ENABLED
TargetCapacity: 90
ManagedTerminationProtection: DISABLED
Dynamic scaling policy for ASG
Current status of the CapacityProviderReservation metric
The CapacityProviderReservation metric has been at 50% for well over 12 hours.
Current status of the Capacity Provider
As you can see, the desired size is still 2, while it is expected that this should have dropped back to 1.
Update
After deleting and recreating the cluster, I notice that the Capacity Provider changes the DesiredCapacity to 2 instantly, even though there are no tasks running.
I am a little hazy about the need for both. I am using both in ECS CloudFormation. It appears that AWS::AutoScaling::AutoScalingGroup is for scaling EC2 instances whereas AWS::ApplicationAutoScaling::ScalableTarget is for scaling containers/tasks. Is my understanding correct?
That is pretty much correct.
AWS::AutoScaling::AutoScalingGroup is used for creating an Auto Scaling group of EC2 instances
AWS::ApplicationAutoScaling::ScalableTarget is used to specify an application resource that can scale - that is any of a range of resources including ECS service, EMR cluster or DynamoDB. A list of all the resources that can be scaled can be found in the ResourceId parameter description for RegisterScalableTarget.
I'm using Ansible to configure AWS Auto Scaling Groups (ASG). Looking at the ec2_asg_module options, there's none for enabling Monitoring in cloudWatch. However, that option can be enabled either form the AWS CLI or the AWS Console.
In the Console, it is labeled as "Group Metric Collection".
Keep in mind that I do not want to monitor the EC2 instances, but the Auto Scaling Group itself.
Thank you.
I submitted a PR last year to add 2 AWS modules : boto3 and boto3_wait.
These 2 modules allow you to interact with AWS API using boto3.
For instance, you could enable group metrics on the ASG by calling enable_metrics_collection method on AutoScaling service :
- name: Enable group metrics
boto3:
service: autoscaling
region: us-east-1
operation: enable_metrics_collection
parameters:
AutoScalingGroupName: my-auto-scaling-group
Granularity: 1Minute
Feel free to give the PR a thumbs-up if you like it! ;)