我想檢視和管理我的 Amazon Elastic Container Service (Amazon ECS) 服務的排程擴展動作。
解決方法
注意: 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,則請參閱對 AWS CLI 進行錯誤疑難排解。此外,請確定您使用的是最新的 AWS CLI 版本。
使用服務自動擴展功能,在特定時間排定 Amazon ECS 服務的最小和最大任務計數。若要設定服務自動擴展功能,您可以使用 Amazon ECS 主控台或 AWS CLI。
請注意,若要使用 AWS CLI 來設定排程的擴展動作,您必須先將 Amazon ECS 服務註冊為可擴展目標。若要檢查 Amazon ECS 服務是否存在可擴展目標,請執行下列 describe-scalable-targets 命令:
aws application-autoscaling describe-scalable-targets \
--service-namespace ecs \
--resource-id service/ecs-cluster/service-name
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name。
如果 Amazon ECS 服務沒有可擴展目標,請執行下列 register-scalable-target 命令來新增一個目標:
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/ecs-cluster/service-name \
--min-capacity 0 \
--max-capacity 0
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name。
若要在 Amazon ECS 主控台中檢視和修改所有排程的擴展動作,請完成下列步驟:
- 開啟 Amazon ECS 主控台。
- 選擇「Service auto scaling」索引標籤。
- 在「Scheduled actions」(已排程動作) 下的「動作」下拉式清單中,選取「檢視」、「編輯」或「刪除」。
若要使用 AWS CLI 建立新的排程擴展動作或修改現有的排程擴展動作,請執行下列 put-scheduled-action 命令:
aws application-autoscaling put-scheduled-action \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/ecs-cluster/service-name \
--scheduled-action-name action-name \
--scalable-target-action MinCapacity=minimum-count,MaxCapacity=maximum-count \
--schedule "schedule"
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name,並使用排程的動作名稱取代 action-name。此外,請使用最小工作計數取代 minimum-count,使用最大計數取代 maximum-count,並以 Rate、Cron 或 At 表達式取代 schedule。
若要使用 AWS CLI 檢視排程的動作,請執行下列 describe-scheduled-actions 命令:
aws application-autoscaling describe-scheduled-actions \
--service-namespace ecs \
--resource-id service/ecs-cluster/service-name
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name。
若要使用 AWS CLI 刪除排程動作,請執行下列 delete-scheduled-action 命令:
aws application-autoscaling delete-scheduled-action \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/ecs-cluster/service-name \
--scheduled-action-name action-name
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name,並使用排程的動作名稱取代 action-name。
如果您刪除 Amazon ECS 服務的所有排程動作,則可以取消註冊該服務,使其不再是可擴展目標。請執行下列 deregister-scalable-target 命令:
aws application-autoscaling deregister-scalable-target \
--service-namespace ecs \
--resource-id service/ecs-cluster/service-name \
--scalable-dimension ecs:service:DesiredCount
**注意:**使用您的叢集名稱取代 ecs-cluster,使用您的服務名稱取代 service-name。