はじめに
fargate でサービスを運用していて、夜間サービスを停止したい時がある。オートスケールの設定を流用することで、夜間停止を行うことができる。
オートスケール設定
1 2 3 4 5 6 7 |
aws application-autoscaling \ register-scalable-target \ --service-namespace ecs \ --resource-id service/{cluster-name}/{service-name} \ --scalable-dimension ecs:service:DesiredCount \ --min-capacity 0 \ --max-capacity 1 |
停止スケジュール
(スケジューリング機能を使い、MinCapacity を 0 にする)
1 2 3 4 5 6 7 |
aws application-autoscaling put-scheduled-action \ --service-namespace ecs \ --resource-id service/{cluster-name}/{service-name} \ --scheduled-action-name poweroff-hogehoge \ --schedule "cron(00 10 ? * * *)" \ --scalable-dimension ecs:service:DesiredCount \ --scalable-target-action MinCapacity=0,MaxCapacity=0 |
起動スケジュール
1 2 3 4 5 6 7 |
aws application-autoscaling put-scheduled-action \ --service-namespace ecs \ --resource-id service/{cluster-name}/{service-name} \ --scheduled-action-name poweron-hogehoge \ --schedule "cron(30 0 ? * MON-FRI *)" \ --scalable-dimension ecs:service:DesiredCount \ --scalable-target-action MinCapacity=1,MaxCapacity=1 |