### Set parameters ```shell $ export ECS_CLUSTER_NAME={YOUR_ECS_CLUSTER_NAME} $ export ECS_SERVICE_NAME={YOUR_ECS_SERVICE_NAME} ``` ### RegisterScalableTarget ```shell $ aws application-autoscaling register-scalable-target --service-namespace ecs \ --scalable-dimension ecs:service:DesiredCount \ --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \ --min-capacity 1 \ --max-capacity 3 ``` ### PutScheduledAction ```shell $ export SCALE_OUT_ACTION_NAME=fargate-time-based-scale-out # configure scaling out $ aws application-autoscaling put-scheduled-action --service-namespace ecs \ --scalable-dimension ecs:service:DesiredCount \ --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \ --scheduled-action-name ${SCALE_OUT_ACTION_NAME} \ --schedule "cron(50 23 * * ? *)" \ # every day at 8:50am JST --scalable-target-action MinCapacity=3,MaxCapacity=10 ``` ```shell $ export SCALE_IN_ACTION_NAME=fargate-time-based-scale-in # configure scaling in $ aws application-autoscaling put-scheduled-action --service-namespace ecs \ --scalable-dimension ecs:service:DesiredCount \ --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \ --scheduled-action-name ${SCALE_IN_ACTION_NAME} \ --schedule "cron(10 9 * * ? *)" \ # every day at 6:10pm JST --scalable-target-action MinCapacity=1,MaxCapacity=1 ``` ### DeleteScheduledAction ```shell $ aws application-autoscaling delete-scheduled-action --service-namespace ecs \ --scheduled-action-name ${SCALE_OUT_ACTION_NAME} \ --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \ --scalable-dimension ecs:service:DesiredCount ``` ```shell $ aws application-autoscaling delete-scheduled-action --service-namespace ecs \ --scheduled-action-name ${SCALE_IN_ACTION_NAME} \ --resource-id service/${ECS_CLUSTER_NAME}/${ECS_SERVICE_NAME} \ --scalable-dimension ecs:service:DesiredCount ``` ### DescribeScheduledActions ```shell $ aws application-autoscaling describe-scheduled-actions --service-namespace ecs \ --scheduled-action-names ${SCALE_IN_ACTION_NAME} ${SCALE_OUT_ACTION_NAME} ``` ### See also https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-scheduled-scaling.html