Skip to content

Instantly share code, notes, and snippets.

@dallasmarlow
Last active November 6, 2020 19:01
Show Gist options
  • Save dallasmarlow/e000b8c0a60a882e9b770e28f8b3e3fb to your computer and use it in GitHub Desktop.
Save dallasmarlow/e000b8c0a60a882e9b770e28f8b3e3fb to your computer and use it in GitHub Desktop.
#!/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