模板名稱
ACS-ECS-ScheduleToStartAndStopInstances 定時開啟和停止ECS執行個體
模板描述
定時開啟和停止ECS執行個體,適用於需要定期管理和調度ECS執行個體的情境,例如開發環境的自動化營運和成本最佳化。在配置過程中,使用者需要提供以下必填參數資訊,地區ID(regionId):用於指定操作執行個體的地區,每天開啟執行個體的時間(dailyStartTime)、每天停止執行個體的時間(dailyStopTime)、任務執行的周期(weekdays):用於定義任務的定時觸發規則。模板在執行後會根據設定的時間表開啟和停止ECS執行個體。
模板類型
自動化
所有者
Alibaba Cloud
輸入參數
參數名稱 | 描述 | 類型 | 是否必填 | 預設值 | 約束 |
dailyStartTime | 每天開啟執行個體的時間 | String | 是 | ||
dailyStopTime | 每天停止執行個體的時間 | String | 是 | ||
targets | 目標執行個體 | Json | 是 | ||
regionId | 地區ID | String | 否 | {{ ACS::RegionId }} | |
weekdays | 任務執行的周期 | String | 否 | MON-FRI | |
triggerEndDate | 時間觸發器結束時間 | String | 否 | 2099-12-01T00:00:00Z | |
stoppedMode | 停機收費模式 | String | 否 | "" | |
hibernate | 執行個體是否休眠 | Boolean | 否 | False | |
rateControl | 任務執行的並發比率 | Json | 否 | {'Mode': 'Concurrency', 'MaxErrors': '100%', 'Concurrency': 10} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | AliyunServiceRoleForOOSInstanceScheduler |
輸出參數
無
執行此模板需要的權限原則
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:StartInstance",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
ACS-ECS-ScheduleToStartAndStopInstances詳情
模板內容
FormatVersion: OOS-2019-06-01
Description:
en: 'Schedule to start and stop ECS instances, applicable to scenarios where regular and scheduled management of ECS instances is required, such as automated operations of development environments and cost optimization. During configuration, users need to provide the following required parameter information: Region ID (regionId), which specifies the region of the ECS instances to be operated on, Daily Start Time (dailyStartTime), Daily Stop Time (dailyStopTime), and the Days of Week (weekdays), which define the schedule for the tasks. Upon execution, the template will start and stop the ECS instances according to the configured schedule.'
zh-cn: 定時開啟和停止ECS執行個體,適用於需要定期管理和調度ECS執行個體的情境,例如開發環境的自動化營運和成本最佳化。在配置過程中,使用者需要提供以下必填參數資訊,地區ID(regionId):用於指定操作執行個體的地區,每天開啟執行個體的時間(dailyStartTime)、每天停止執行個體的時間(dailyStopTime)、任務執行的周期(weekdays):用於定義任務的定時觸發規則。模板在執行後會根據設定的時間表開啟和停止ECS執行個體。
name-en: ACS-ECS-ScheduleToStartAndStopInstances
name-zh-cn: 定時開啟和停止ECS執行個體
categories:
- time_trigger
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地區ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
dailyStartTime:
Label:
en: DailyStartTime
zh-cn: 每天開啟執行個體的時間
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
dailyStopTime:
Label:
en: DailyStopTime
zh-cn: 每天停止執行個體的時間
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
weekdays:
Label:
en: Weekdays
zh-cn: 任務執行的周期
Description:
en: '* indicates daily, MON indicates Monday only, MON-FRI indicates Monday to Friday,refer them here: https://www.alibabacloud.com/help/document_detail/169784.html'
zh-cn: '*表示每天,MON表示僅周一,MON-FRI表示周一到周五。詳情參考:https://www.alibabacloud.com/help/document_detail/169784.html'
Type: String
Default: MON-FRI
triggerEndDate:
Label:
en: TriggerEndDate
zh-cn: 時間觸發器結束時間
Description:
en: 'Format: yyyy-MM-ddTHH:mm:ssZ.'
zh-cn: '格式:yyyy-MM-ddTHH:mm:ssZ'
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'YYYY-MM-DDTHH:mm:ssZ'
Default: '2099-12-01T00:00:00Z'
targets:
Type: Json
Label:
en: TargetInstance
zh-cn: 目標執行個體
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
stoppedMode:
Label:
en: StoppedMode
zh-cn: 停機收費模式
Description:
en: Indicates whether the ECS instance is still charged after it is stopped
zh-cn: 停止隨用隨付ECS執行個體後,是否繼續計費
Type: String
AllowedValues:
- StopCharging
- KeepCharging
- ''
Default: ''
hibernate:
Label:
en: WhetherToHibernateTheInstance
zh-cn: 執行個體是否休眠
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: 任務執行的並發比率
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 100%
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: OOS扮演的RAM角色
Type: String
Default: AliyunServiceRoleForOOSInstanceScheduler
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: timerTrigger
Action: 'ACS::TimerTrigger'
Description:
en: Triggers a task as scheduled by specifying Cron expression
zh-cn: 通過指定Cron運算式按計劃觸發任務
Properties:
Type: cron
EndDate: '{{ triggerEndDate }}'
Expression:
'Fn::Join':
- ' '
- - '0'
- 'Fn::Select':
- 1
- 'Fn::Split':
- ':'
- '{{ dailyStartTime }}'
- 'Fn::Select':
- 0
- 'Fn::Split':
- ':'
- '{{ dailyStartTime }}'
- '?'
- '*'
- '{{ weekdays }}'
- Name: getInstance
Description:
en: Views the ECS instances
zh-cn: 擷取ECS執行個體
Action: 'ACS::SelectTargets'
Properties:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: '{{regionId}}'
Filters:
- '{{ targets }}'
Outputs:
instanceIds:
Type: List
ValueSelector: 'Instances.Instance[].InstanceId'
- Name: startInstance
Action: 'ACS::ECS::StartInstance'
Description:
en: Starts the ECS instances
zh-cn: 開啟執行個體
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'
- Name: sleepToSpecifiedTime
Description:
en: Sleep to instance stop time
zh-cn: 睡眠到執行個體停止時間
Action: 'ACS::Sleep'
Properties:
Duration:
'Fn::DurationBetween':
- '{{ dailyStartTime }}'
- '{{ dailyStopTime }}'
- Name: stopInstance
Action: 'ACS::ECS::StopInstance'
Description:
en: Stops the ECS instances
zh-cn: 停止執行個體
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
stoppedMode: '{{ stoppedMode }}'
hibernate: '{{ hibernate }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'