本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 建立 Application Auto Scaling 的排程動作 AWS CLI
下列範例示範如何使用 AWS CLI put-scheduled-action 命令建立排程動作。指定新的容量時,可指定最低容量、最高容量或一併指定最低和最高容量。
這些範例針對與 Application Auto Scaling 整合的幾個服務使用可擴展的目標。若要使用不同的可擴展目標,請在 中指定其命名空間--service-namespace、在 中指定其可擴展維度--scalable-dimension,以及在 中指定其資源 ID--resource-id。
使用 時 AWS CLI,請記住,您的命令會在為您的設定檔 AWS 區域 設定的 中執行。如果您想在不同區域中執行命令,則可變更設定檔的預設區域,或搭配 --region 參數使用命令。
建立只發生一次的排程動作
若只要在指定的日期和時間自動擴展可擴展的目標一次,請使用 --schedule "at( 選項。yyyy-mm-ddThh:mm:ss)"
範例:僅擴增一次
以下是建立排定動作在特定日期和時間水平擴展容量的範例。
在 --schedule 指定的日期和時間 (2021 年 3 月 31 日下午 10 點 UTC),如果 MinCapacity 指定的值高於目前的容量,則 Application Auto Scaling 會水平擴展至 MinCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource\ --scalable-dimensioncustom-resource:ResourceType:Property\ --resource-idfile://~/custom-resource-id.txt\ --scheduled-action-namescale-out\ --schedule "at(2021-03-31T22:00:00)" \ --scalable-target-action MinCapacity=3
Windows
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource^ --scalable-dimensioncustom-resource:ResourceType:Property^ --resource-idfile://~/custom-resource-id.txt^ --scheduled-action-namescale-out^ --schedule "at(2021-03-31T22:00:00)" ^ --scalable-target-action MinCapacity=3
執行此排定的動作時,如果容量上限小於容量下限指定的值,則您必須指定新的容量上限和下限,而不只是容量下限。
範例:僅縮減一次
以下是建立排定動作在特定日期和時間縮減容量的範例。
在 --schedule 指定的日期和時間 (2021 年 3 月 31 日下午 10 點 30 分 UTC),如果 MaxCapacity 指定的值低於目前的容量,則 Application Auto Scaling 會縮減至 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource\ --scalable-dimensioncustom-resource:ResourceType:Property\ --resource-idfile://~/custom-resource-id.txt\ --scheduled-action-namescale-in\ --schedule "at(2021-03-31T22:30:00)" \ --scalable-target-action MinCapacity=0,MaxCapacity=0
Windows
aws application-autoscaling put-scheduled-action --service-namespacecustom-resource^ --scalable-dimensioncustom-resource:ResourceType:Property^ --resource-idfile://~/custom-resource-id.txt^ --scheduled-action-namescale-in^ --schedule "at(2021-03-31T22:30:00)" ^ --scalable-target-action MinCapacity=0,MaxCapacity=0
建立依週期性間隔執行的排定動作
若要依據週期性間隔來執行排程擴展,請使用 --schedule
"rate( 選項。其值必須為正整數。單位可以是 value unit)"minute、minutes、hour、hours、day 或 days。如需詳細資訊,請參閱《Amazon EventBridge 使用者指南》中的 Rate 運算式。
以下是使用 Rate 表達式的排定動作範例。
按照指定的排程 (從 2021 年 1 月 30 日下午中午 12 點 UTC 開始至 2021 年 1 月 31 日下午 10 點 UTC 結束,每隔 5 小時),如果 MinCapacity 指定的值高於目前的容量,則 Application Auto Scaling 會水平擴展至 MinCapacity。如果 MaxCapacity 指定的值低於目前的容量,則 Application Auto Scaling 會縮減至 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespaceecs\ --scalable-dimensionecs:service:DesiredCount\ --resource-idservice/my-cluster/my-service\ --scheduled-action-namemy-recurring-action\ --schedule "rate(5 hours)" \ --start-time2021-01-30T12:00:00\ --end-time2021-01-31T22:00:00\ --scalable-target-action MinCapacity=3,MaxCapacity=10
Windows
aws application-autoscaling put-scheduled-action --service-namespaceecs^ --scalable-dimensionecs:service:DesiredCount^ --resource-idservice/my-cluster/my-service^ --scheduled-action-namemy-recurring-action^ --schedule "rate(5 hours)" ^ --start-time2021-01-30T12:00:00^ --end-time2021-01-31T22:00:00^ --scalable-target-action MinCapacity=3,MaxCapacity=10
建立依週期性排程執行的排程動作
若要依據週期性排程來執行排程擴展,請使用 --schedule
"cron( 選項。如需詳細資訊,請參閱使用 Application Auto Scaling 排程週期性擴展動作。fields)"
以下是使用 Rate 表達式的排定動作範例。
按照指定的排程 (每天上午 9 點 UTC),如果 MinCapacity 指定的值高於目前的容量,則 Application Auto Scaling 會水平擴展至 MinCapacity。如果 MaxCapacity 指定的值低於目前的容量,則 Application Auto Scaling 會縮減至 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespaceappstream\ --scalable-dimensionappstream:fleet:DesiredCapacity\ --resource-idfleet/sample-fleet\ --scheduled-action-namemy-recurring-action\ --schedule "cron(0 9 * * ? *)" \ --scalable-target-action MinCapacity=10,MaxCapacity=50
Windows
aws application-autoscaling put-scheduled-action --service-namespaceappstream^ --scalable-dimensionappstream:fleet:DesiredCapacity^ --resource-idfleet/sample-fleet^ --scheduled-action-namemy-recurring-action^ --schedule "cron(0 9 * * ? *)" ^ --scalable-target-action MinCapacity=10,MaxCapacity=50
建立一次性排定動作並指定時區
排定的動作預設為 UTC 時區。若要指定不同的時區,請包含 --timezone 選項,並指定時區的正式名稱 (例如 America/New_York)。如需詳細資訊,請參閱 https://www.joda.org/joda-time/timezones.html
以下是建立排定動作在特定日期和時間擴展容量時使用 --timezone 選項的範例。
在 --schedule 指定的日期和時間 (2021 年 1 月 31 日下午 5 點當地時間),如果 MinCapacity 指定的值高於目前的容量,則 Application Auto Scaling 會水平擴展至 MinCapacity。如果 MaxCapacity 指定的值低於目前的容量,則 Application Auto Scaling 會縮減至 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespacecomprehend\ --scalable-dimensioncomprehend:document-classifier-endpoint:DesiredInferenceUnits\ --resource-idarn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE\ --scheduled-action-namemy-one-time-action\ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" \ --scalable-target-action MinCapacity=1,MaxCapacity=3
Windows
aws application-autoscaling put-scheduled-action --service-namespacecomprehend^ --scalable-dimensioncomprehend:document-classifier-endpoint:DesiredInferenceUnits^ --resource-idarn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE^ --scheduled-action-namemy-one-time-action^ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" ^ --scalable-target-action MinCapacity=1,MaxCapacity=3
建立指定時區的週期性排程動作
以下範例使用 --timezone 選項,在建立週期性排程動作時擴展容量。如需詳細資訊,請參閱使用 Application Auto Scaling 排程週期性擴展動作。
按照指定的排程 (每週一到週五下午 6 點當地時間),如果 MinCapacity 指定的值高於目前的容量,則 Application Auto Scaling 會水平擴展至 MinCapacity。如果 MaxCapacity 指定的值低於目前的容量,則 Application Auto Scaling 會縮減至 MaxCapacity。
Linux、macOS 或 Unix
aws application-autoscaling put-scheduled-action --service-namespacelambda\ --scalable-dimensionlambda:function:ProvisionedConcurrency\ --resource-idfunction:my-function:BLUE\ --scheduled-action-namemy-recurring-action\ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" \ --scalable-target-action MinCapacity=10,MaxCapacity=50
Windows
aws application-autoscaling put-scheduled-action --service-namespacelambda^ --scalable-dimensionlambda:function:ProvisionedConcurrency^ --resource-idfunction:my-function:BLUE^ --scheduled-action-namemy-recurring-action^ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" ^ --scalable-target-action MinCapacity=10,MaxCapacity=50