Template name
ACS-ECS-ScheduleToStopAndStartInstances
Template description
Stops and then starts Elastic Compute Service (ECS) instances as scheduled. This applies to scenarios in which you want to stop and start ECS instances at the specified time, such as automated O&M and resource management. When you configure this template, you must specify the following parameters: regionId: the region of the ECS instances, dailyStopTime: the time when the ECS instances to be stopped, dailyStartTime: the time when the ECS instances to be started, weekdays: the duration of the task, and targets: the specific ECS instances to be stopped and started. In addition, you can specify whether to stop or hibernate the ECS instances.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
dailyStopTime | The time when the instances are stopped each day. | String | Yes | ||
dailyStartTime | The time when the instances are started each day. | String | Yes | ||
targets | The ECS instances to be stopped and started. | Json | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
weekdays | The interval at which the task is executed. | String | No | MON-FRI | |
triggerEndDate | The end time of the scheduled task. | String | No | 2099-12-01T00:00:00Z | |
stoppedMode | Specifies whether to charge the ECS instances after they are stopped. | String | No | "" | |
hibernate | Specifies whether to hibernate the ECS instances. | Boolean | No | False | |
rateControl | The rate control settings. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': '100%', 'Concurrency': 10} | |
OOSAssumeRole | The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS). | String | No | AliyunServiceRoleForOOSInstanceScheduler |
Output parameters
None
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:StartInstance",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
References
For more information, see ACS-ECS-ScheduleToStopAndStartInstances.yml at GitHub.
Template content
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: the description in Chinese
name-en: ACS-ECS-ScheduleToStopAndStartInstances
zh-cn: the description in Chinese
categories:
- time_trigger
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: the description in Chinese
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
dailyStopTime:
Label:
en: DailyStopTime
zh-cn: the description in Chinese
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
dailyStartTime:
Label:
en: DailyStartTime
zh-cn: the description in Chinese
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
weekdays:
Label:
en: Weekdays
zh-cn: the description in Chinese
Description:
en: '* indicates daily, MON indicates Monday only, MON-FRI indicates Monday to Friday. Refer them here: https://help.aliyun.com/document_detail/169784.html'
zh-cn: the description in Chinese
Type: String
Default: MON-FRI
triggerEndDate:
Label:
en: TriggerEndDate
zh-cn: the description in Chinese
Description:
en: 'Format: yyyy-MM-ddTHH:mm:ssZ.'
zh-cn: the description in Chinese
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: the description in Chinese
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
stoppedMode:
Label:
en: StoppedMode
zh-cn: the description in Chinese
Description:
en: Indicates whether the ECS instance is still charged after it is stopped
zh-cn: the description in Chinese
Type: String
AllowedValues:
- StopCharging
- KeepCharging
- ''
Default: ''
hibernate:
Label:
en: WhetherToHibernateTheInstance
zh-cn: the description in Chinese
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: the description in Chinese
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 100%
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
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: the description in Chinese
Action: 'ACS::Sleep'
Properties:
Duration:
'Fn::DurationBetween':
- '{{ dailyStopTime }}'
- '{{ dailyStartTime }}'
- Name: startInstance
Action: 'ACS::ECS::StartInstance'
Description:
en: Starts the ECS instances
zh-cn: the description in Chinese
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'