- jq
- aws cli
Show Auto Scaling policies
ecs-autoscaling show policy
Show Auto Scaling target
ecs-autoscaling show policy
Apply Auto Scaling policy & target
ecs-autoscaling show policy path/to/files
{ | |
"cluster": "connected-base-dev", | |
"service": "web", | |
"min_capacity": 1, | |
"max_capacity": 4 | |
} |
#!/bin/bash | |
set -eu -o pipefail | |
ProgName=$(basename $0) | |
sub_help() { | |
echo "Usage: $ProgName <subcommand>" | |
echo "" | |
echo "Subcommands:" | |
echo " show" | |
echo " apply" | |
echo "" | |
echo "Example:" | |
echo " $ProgName show target" | |
echo " $ProgName show policy" | |
echo " $ProgName apply <path>" | |
echo "" | |
exit 1 | |
} | |
sub_show() { | |
Type=${1:-""} | |
case $Type in | |
target) | |
aws application-autoscaling describe-scalable-targets --service-namespace ecs | |
;; | |
policy) | |
aws application-autoscaling describe-scaling-policies --service-namespace ecs | |
;; | |
*) | |
echo "Usage: $ProgName show {target|policy}" | |
echo "" | |
;; | |
esac | |
} | |
as_policy_name="ecs-service-scaling" | |
sub_apply() { | |
set -x | |
path=${1:-""} | |
if [ -z "$path" ]; then | |
echo "path is required" | |
exit 1 | |
fi | |
cluster=$(jq -r '.cluster' $path/config.json) | |
service=$(jq -r '.service' $path/config.json) | |
min_capacity=$(jq -r '.min_capacity' $path/config.json) | |
max_capacity=$(jq -r '.max_capacity' $path/config.json) | |
aws application-autoscaling register-scalable-target \ | |
--service-namespace ecs \ | |
--resource-id service/$cluster/$service \ | |
--scalable-dimension ecs:service:DesiredCount \ | |
--min-capacity $min_capacity \ | |
--max-capacity $max_capacity | |
aws application-autoscaling put-scaling-policy \ | |
--service-namespace ecs \ | |
--resource-id service/$cluster/$service \ | |
--scalable-dimension ecs:service:DesiredCount \ | |
--policy-name $as_policy_name \ | |
--policy-type TargetTrackingScaling \ | |
--target-tracking-scaling-policy-configuration file://$path/policy.json | |
} | |
subcommand=${1:-""} | |
case $subcommand in | |
"" | "-h" | "--help" | "help") | |
sub_help | |
;; | |
*) | |
shift | |
sub_${subcommand} $@ | |
if [ $? = 127 ]; then | |
echo "Error: '$subcommand' is not a known subcommand." >&2 | |
echo " Run '$ProgName --help' for a list of known subcommands." >&2 | |
exit 1 | |
fi | |
;; | |
esac |
{ | |
"TargetValue": 60.0, | |
"PredefinedMetricSpecification": { | |
"PredefinedMetricType": "ECSServiceAverageCPUUtilization" | |
} | |
} |