Template name
ACS-ECS-ScheduleToStartAndStopInstances
Template description
Starts and then stops Elastic Compute Service (ECS) instances as scheduled.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Type | Required | Default value | Limit |
dailyStartTime | The time when the ECS instances are started each day. | String | Yes | ||
dailyStopTime | The time when the ECS instances are stopped each day. | String | Yes | ||
targets | The ECS instances to be started and stopped. | Json | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
weekdays | The cycle of the scheduled task. | 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-ScheduleToStartAndStopInstances.yml at GitHub.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Schedule to start and stop ECS instances
zh-cn: the description in Chinese
name-en: ACS-ECS-ScheduleToStartAndStopInstances
name-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 }}'
dailyStartTime:
Label:
en: DailyStartTime
zh-cn: the description in Chinese
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
dailyStopTime:
Label:
en: DailyStopTime
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':
- ':'
- '{{ dailyStartTime }}'
- 'Fn::Select':
- 0
- 'Fn::Split':
- ':'
- '{{ dailyStartTime }}'
- '?'
- '*'
- '{{ 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: 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 }}'
- Name: sleepToSpecifiedTime
Description:
en: Sleep to instance stop time
zh-cn: the description in Chinese
Action: 'ACS::Sleep'
Properties:
Duration:
'Fn::DurationBetween':
- '{{ dailyStartTime }}'
- '{{ dailyStopTime }}'
- 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 }}'