Template name
ACS-ECS-ScheduleToStopAndStartInstances: Schedules to stop and start ECS instances
Template description
This template stops and starts Elastic Compute Service (ECS) instances on a schedule, which is useful for automated Operations and Maintenance (O&M) and resource management. To use the template, configure the required parameters: region ID (regionId), daily stop time (dailyStopTime), daily start time (dailyStartTime), days of the week (weekdays), and target instances (targets). You can also choose to hibernate the instances. The template then stops and starts the ECS instances based on your schedule.
Template type
Automation
Owner
Alibaba Cloud
Input parameters
Parameter name | Description | Type | Required | Default value | Constraints |
dailyStopTime | The time to stop the instances each day. | String | Yes | ||
dailyStartTime | The time to start the instances each day. | String | Yes | ||
targets | The target instances. | Json | Yes | ||
regionId | The ID of the region. | String | No | {{ ACS::RegionId }} | |
weekdays | The days of the week to run the task. | String | No | MON-FRI | |
triggerEndDate | The time when the trigger expires. | String | No | 2099-12-01T00:00:00Z | |
stoppedMode | The billing mode for a stopped pay-as-you-go instance. | String | No | "" | |
hibernate | Specifies whether to hibernate the instance. | Boolean | No | False | |
rateControl | The concurrency rate for task execution. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': '100%', 'Concurrency': 10} | |
OOSAssumeRole | The RAM role that Operation Orchestration Service (OOS) assumes. | String | No | AliyunServiceRoleForOOSInstanceScheduler |
Output parameters
None
Required access policy
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:StartInstance",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
For more information, see ACS-ECS-ScheduleToStopAndStartInstances.
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, along with 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: 'Schedules to stop and start ECS instances. This template is applicable to scenarios that require automatically stopping and starting ECS instances at specific times, such as automated O&M tasks and resource management. During configuration, you must provide the following required parameters: Region ID (regionId), which specifies the region of the ECS instances to be operated on; Daily Stop Time (dailyStopTime) and Daily Start Time (dailyStartTime); Days of Week (weekdays), which defines the schedule for the tasks; and Target Instances (targets), which defines the specific ECS instances to be operated on. You can also choose whether to stop or hibernate the instances. The template will stop and start the ECS instances according to the configured schedule.'
name-en: ACS-ECS-ScheduleToStopAndStartInstances
name-zh-cn: Schedule to stop and start ECS instances
categories:
- time_trigger
Parameters:
regionId:
Type: String
Label:
en: RegionId
zh-cn: Region ID
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
dailyStopTime:
Label:
en: DailyStopTime
zh-cn: Daily stop time
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
dailyStartTime:
Label:
en: DailyStartTime
zh-cn: Daily start time
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'HH:mm:ssZ'
weekdays:
Label:
en: Weekdays
zh-cn: Task execution cycle
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: '* indicates daily, MON indicates Monday only, MON-FRI indicates Monday to Friday. For more information, see: https://www.alibabacloud.com/help/document_detail/169784.html'
Type: String
Default: MON-FRI
triggerEndDate:
Label:
en: TriggerEndDate
zh-cn: Trigger end time
Description:
en: 'Format: yyyy-MM-ddTHH:mm:ssZ.'
zh-cn: 'Format: 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: Target instance
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
stoppedMode:
Label:
en: StoppedMode
zh-cn: Stopped mode
Description:
en: Indicates whether the ECS instance is still charged after it is stopped
zh-cn: Specifies whether to continue billing for a pay-as-you-go ECS instance after it is stopped.
Type: String
AllowedValues:
- StopCharging
- KeepCharging
- ''
Default: ''
hibernate:
Label:
en: WhetherToHibernateTheInstance
zh-cn: Whether to hibernate the instance
Type: Boolean
Default: false
rateControl:
Label:
en: RateControl
zh-cn: Task execution concurrency rate
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 100%
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
zh-cn: RAM role assumed by OOS
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: Triggers a task on a schedule by specifying a cron expression.
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: Gets ECS instances.
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: Stops instances.
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: Sleeps until the instance start time.
Action: 'ACS::Sleep'
Properties:
Duration:
'Fn::DurationBetween':
- '{{ dailyStopTime }}'
- '{{ dailyStartTime }}'
- Name: startInstance
Action: 'ACS::ECS::StartInstance'
Description:
en: Starts the ECS instances
zh-cn: Starts instances.
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'