Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/sh
- AWS_PROFILE=<region>
- AWS_DEFAULT_REGION=<region>
- if [[ $1 = "start" ]]; then
- # The additional star at the end of the line avoids the \n at the end of the $desired variable
- aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?Tags[?Key=='\''Owner'\'' && Value=='\''kops'\'']].[AutoScalingGroupName,MinSize,MaxSize,DesiredCapacity,'\''*'\'']' --output text | while IFS= read -r line
- do
- read -r name min max desired _<<< "$line"
- if [[ $desired -eq 0 ]] ; then
- printf "Raising autoscaling %s to %s.\n" "$name" "$max"
- aws autoscaling set-desired-capacity --auto-scaling-group-name $name --desired-capacity $max
- fi
- done
- elif [[ $1 = "stop" ]]; then
- aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?Tags[?Key=='\''Owner'\'' && Value=='\''kops'\'']].[AutoScalingGroupName,MinSize,MaxSize,DesiredCapacity,'\''*'\'']' --output text | while IFS= read -r line
- do
- read -r name min max desired _<<< "$line"
- if [[ $desired -eq 0 ]] ; then
- printf "Stopping autoscaling %s.\n" "$name" "$max"
- aws autoscaling update-auto-scaling-group --auto-scaling-group-name $name --min-size 0
- aws autoscaling set-desired-capacity --auto-scaling-group-name $name --desired-capacity 0
- fi
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement