ACS-ECS-ScheduleToStopAndStartInstances
模板名稱
ACS-ECS-ScheduleToStopAndStartInstances 定時停止和開啟ECS實例
模板描述
定時停止和開啟ECS實例,適用于需要在特定時間段自動停止和啟動ECS實例的場景,如自動化運維任務(wù)和資源管理。在配置過程中,用戶需要提供以下必填參數(shù)信息:地域ID(regionId):用于指定需要操作的ECS實例所在的地域,每天停止實例的時間(dailyStopTime)和每天開啟實例的時間(dailyStartTime)、任務(wù)執(zhí)行的周期(weekdays):用于定義任務(wù)的定時觸發(fā)規(guī)則,以及目標實例(targets):用于定義具體需要操作的ECS實例。用戶還可以選擇是否停止或休眠實例。模板會根據(jù)設(shè)置的時間表定時停止和啟動ECS實例。
模板類型
自動化
所有者
Alibaba Cloud
輸入?yún)?shù)
參數(shù)名稱 | 描述 | 類型 | 是否必填 | 默認值 | 約束 |
dailyStopTime | 每天停止實例的時間 | String | 是 | ||
dailyStartTime | 每天開啟實例的時間 | String | 是 | ||
targets | 目標實例 | Json | 是 | ||
regionId | 地域ID | String | 否 | {{ ACS::RegionId }} | |
weekdays | 任務(wù)執(zhí)行的周期 | String | 否 | MON-FRI | |
triggerEndDate | 時間觸發(fā)器結(jié)束時間 | String | 否 | 2099-12-01T00:00:00Z | |
stoppedMode | 停機收費模式 | String | 否 | “” | |
hibernate | 實例是否休眠 | Boolean | 否 | False | |
rateControl | 任務(wù)執(zhí)行的并發(fā)比率 | Json | 否 | {‘Mode’: ‘Concurrency’, ‘MaxErrors’: ‘100%’, ‘Concurrency’: 10} | |
OOSAssumeRole | OOS扮演的RAM角色 | String | 否 | AliyunServiceRoleForOOSInstanceScheduler |
輸出參數(shù)
無
執(zhí)行此模板需要的權(quán)限策略
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:StartInstance",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
詳情
ACS-ECS-ScheduleToStopAndStartInstances詳情
模板內(nèi)容
FormatVersion: OOS-2019-06-01
Description:
en: 'Schedules to stop and start ECS instances, applicable to scenarios that require automatically stopping and starting ECS instances at specific times, such as automated maintenance tasks and resource management. 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 Stop Time (dailyStopTime) and Daily Start Time (dailyStartTime), and Days of Week (weekdays), which define the schedule for the tasks, as well as Target Instances (targets), which define the specific ECS instances to be operated on. Users can also choose whether to stop or hibernate the instances. The template will stop and start the ECS instances according to the configured schedule.'
zh-cn: 定時停止和開啟ECS實例,適用于需要在特定時間段自動停止和啟動ECS實例的場景,如自動化運維任務(wù)和資源管理。在配置過程中,用戶需要提供以下必填參數(shù)信息:地域ID(regionId):用于指定需要操作的ECS實例所在的地域,每天停止實例的時間(dailyStopTime)和每天開啟實例的時間(dailyStartTime)、任務(wù)執(zhí)行的周期(weekdays):用于定義任務(wù)的定時觸發(fā)規(guī)則,以及目標實例(targets):用于定義具體需要操作的ECS實例。用戶還可以選擇是否停止或休眠實例。模板會根據(jù)設(shè)置的時間表定時停止和啟動ECS實例。
name-en: ACS-ECS-ScheduleToStopAndStartInstances
name-zh-cn: 定時停止和開啟ECS實例
categories:
- time_trigger
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: 地域ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
dailyStopTime:
Label:
en: DailyStopTime
zh-cn: 每天停止實例的時間
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
dailyStartTime:
Label:
en: DailyStartTime
zh-cn: 每天開啟實例的時間
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
weekdays:
Label:
en: Weekdays
zh-cn: 任務(wù)執(zhí)行的周期
Description:
en: '* indicates daily, MON indicates Monday only, MON-FRI indicates Monday to Friday,refer them here: http://bestwisewords.com/document_detail/169784.html'
zh-cn: '*表示每天,MON表示僅周一,MON-FRI表示周一到周五。詳情參考:http://bestwisewords.com/document_detail/169784.html'
Type: String
Default: MON-FRI
triggerEndDate:
Label:
en: TriggerEndDate
zh-cn: 時間觸發(fā)器結(jié)束時間
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實例后,是否繼續(xù)計費
Type: String
AllowedValues:
- StopCharging
- KeepCharging
- ''
Default: ''
hibernate:
Label:
en: WhetherToHibernateTheInstance
zh-cn: 實例是否休眠
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: 任務(wù)執(zhí)行的并發(fā)比率
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表達式按計劃觸發(fā)任務(wù)
Properties:
Type: cron
EndDate: '{{ triggerEndDate }}'
Expression:
'Fn::Join':
- ' '
- - '0'
- 'Fn::Select':
- 1
- 'Fn::Split':
- ':'
- '{{ dailyStopTime }}'
- 'Fn::Select':
- 0
- 'Fn::Split':
- ':'
- '{{ dailyStopTime }}'
- '?'
- '*'
- '{{ 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: 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 }}'
- Name: sleepToSpecifiedTime
Description:
en: Sleep to instance start time
zh-cn: 睡眠到實例開啟時間
Action: 'ACS::Sleep'
Properties:
Duration:
'Fn::DurationBetween':
- '{{ dailyStopTime }}'
- '{{ dailyStartTime }}'
- 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 }}'