Advertisement
Javi

AWS: CLI for starting/stopping kops clusters

Apr 4th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #/bin/sh
  2.  
  3. AWS_PROFILE=<region>
  4. AWS_DEFAULT_REGION=<region>
  5.  
  6.  
  7. if [[ $1 = "start" ]]; then
  8. # The additional star at the end of the line avoids the \n at the end of the $desired variable
  9. aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?Tags[?Key=='\''Owner'\'' && Value=='\''kops'\'']].[AutoScalingGroupName,MinSize,MaxSize,DesiredCapacity,'\''*'\'']' --output text | while IFS= read -r line
  10. do
  11. read -r name min max desired _<<< "$line"
  12. if [[ $desired -eq 0 ]] ; then
  13. printf "Raising autoscaling %s to %s.\n" "$name" "$max"
  14. aws autoscaling set-desired-capacity --auto-scaling-group-name $name --desired-capacity $max
  15. fi
  16. done
  17. elif [[ $1 = "stop" ]]; then
  18. aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?Tags[?Key=='\''Owner'\'' && Value=='\''kops'\'']].[AutoScalingGroupName,MinSize,MaxSize,DesiredCapacity,'\''*'\'']' --output text | while IFS= read -r line
  19. do
  20. read -r name min max desired _<<< "$line"
  21. if [[ $desired -eq 0 ]] ; then
  22. printf "Stopping autoscaling %s.\n" "$name" "$max"
  23. aws autoscaling update-auto-scaling-group --auto-scaling-group-name $name --min-size 0
  24. aws autoscaling set-desired-capacity --auto-scaling-group-name $name --desired-capacity 0
  25. fi
  26. done
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement