Questions tagged with AWS Auto Scaling

Content language: English

Sort by most recent

Browse through the questions and answers listed below or filter and sort to narrow down your results.

Elastic beanstalk custom scaling policy

Currently i'm working on scaling my elastic beanstalk environment based on memory_used metric. Based on research i found out that i need to create the scaling policy and attach it to the alarm in the postdeploy hooks, as cloudwatch agent is needed to collect the mem_used_percent metric. So this is what i've done so far: 1- In the .ebextentions i created a config file for the clowdwatch agent. 2- In the .platform/hooks/postdeploy i created a .sh script to create the policy and clowdwatch alarm note: I'm using Immutable updates for the elastic beanstalk environment The issue i have is that when i print the Autoscaling group name i find out that it prints the temporary autoscaling group name not the permanent one so the policy isn't created. How i can fix it ? ``` #!/bin/bash sudo yum install jq INSTANCE="`wget -qO-`" Region="`curl --silent | jq -r .region`" Account="`curl -s | jq -r .accountId`" AutoScalingGroup="`aws autoscaling describe-auto-scaling-instances --instance-ids $INSTANCE --query 'AutoScalingInstances[0].AutoScalingGroupName' --region $Region`" echo "Printing AutoScalingGroup - Create_scaling" echo "$AutoScalingGroup" #Create scale up policy aws autoscaling put-scaling-policy --auto-scaling-group-name $AutoScalingGroup --policy-name my-simple-scale-up-policy-2 --policy-type SimpleScaling --adjustment-type ChangeInCapacity --scaling-adjustment 1 --cooldown 60 --region $Region PolicyUp="`aws autoscaling describe-policies --auto-scaling-group-name $AutoScalingGroup --region $Region --query 'ScalingPolicies[?PolicyName==`my-simple-scale-up-policy-2`].PolicyARN | [0] ' `" #Create alarm on memory and link with scale up policy aws cloudwatch put-metric-alarm --region=$Region \ --alarm-name 1ScalingMemSpaceUtilization\ --alarm-description "Alarm when MemSpaceUtilization exceeds 80 percent" \ --metric-name mem_used_percent --namespace CWAgent --statistic Average \ --period 300 --threshold 80 --comparison-operator GreaterThanThreshold \ --dimensions Name=AutoScalingGroupName,Value=$AutoScalingGroup Name=InstanceId,Value=$INSTANCE --evaluation-periods 1 \ --alarm-actions $PolicyUp --unit Percent ``` * The AutoScalingGroup varaible is used to get the name of the current autoscaling group. * The PolicyUp variable is used to get the ARN of the created policy to be linked with the alarm, so when the alarm is "IN ALARM" state it triggers the scaling policy.
asked 3 months ago