Last active
November 6, 2020 19:01
-
-
Save dallasmarlow/e000b8c0a60a882e9b770e28f8b3e3fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -ex | |
DATE_FMT="%Y-%m-%dT%H:%M:%SZ" | |
MIN_ASG_INSTANCES=${MIN_ASG_INSTANCES:-0} | |
OUTPUT_KEY=${OUTPUT_KEY:=eks_compute_asg_name} | |
cd projects/eks-compute | |
ASG_NAME=$(terraform output $OUTPUT_KEY) | |
cd - | |
case $1 in | |
activity) | |
aws autoscaling describe-scaling-activities \ | |
--auto-scaling-group-name $ASG_NAME | |
;; | |
refresh) | |
aws autoscaling start-instance-refresh \ | |
--auto-scaling-group-name my-asg \ | |
--preferences '{"InstanceWarmup": 60}' | |
;; | |
scale) | |
instances=${2:-1} | |
aws autoscaling set-desired-capacity \ | |
--auto-scaling-group-name $ASG_NAME \ | |
--desired-capacity $instances | |
;; | |
scale-interval) | |
instances=${2:-1} | |
interval=${3:-1} | |
aws autoscaling put-scheduled-update-group-action \ | |
--auto-scaling-group-name $ASG_NAME \ | |
--min-size $instances \ | |
--scheduled-action-name eks-compute-scale-up \ | |
--start-time $(date -d "+5 second" -u +$DATE_FMT) | |
aws autoscaling put-scheduled-update-group-action \ | |
--auto-scaling-group-name $ASG_NAME \ | |
--min-size $MIN_ASG_INSTANCES \ | |
--desired-capacity $MIN_ASG_INSTANCES \ | |
--scheduled-action-name eks-compute-scale-down \ | |
--start-time $(date -d "+${interval} hour" -u +$DATE_FMT) | |
;; | |
*) | |
echo "usage: $0 <activity|refresh|scale $num_instances|scale-interval $num_instances $hours>" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment