Template name
ACS-ECS-ScheduleToStopInstances: Stop ECS instances on a schedule
Template description
This template stops Elastic Compute Service (ECS) instances on a schedule. You can use it to automatically shut down development or test environments to save costs. When you configure the template, specify the required region ID, cron expression, and target instances. The template then stops the specified instances based on the defined schedule.
Template type
Automation
Owner
Alibaba Cloud
Input parameters
Parameter name | Description | Type | Required | Default value | Constraints |
endDate | The end time of the timer trigger. | String | Yes | ||
targets | The target instances. | Json | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
cron | The cron expression. | String | No | 0 0 12 ? * * | |
timeZone | The time zone. | String | No | UTC | |
rateControl | The concurrency rate for the task execution. | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | The Resource Access Management (RAM) role that Operation Orchestration Service (OOS) assumes. | String | No | OOSServiceRole |
Output parameters
Parameter name | Description | Type |
instanceIds | List |
Required permissions
{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:DescribeInstances",
"ecs:StopInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
For more information, see ACS-ECS-ScheduleToStopInstances details.
Template content
FormatVersion: OOS-2019-06-01
Description:
en: 'Schedule to stop the ECS instances, applicable to scenarios where ECS instances need to be stopped at scheduled times, such as automatically stopping development or test environments to save costs. 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, Cron Expression (cron), which defines the schedule for the task, and Target Instances (targets), which defines the specific ECS instances to be operated on. Upon execution, the template will stop the ECS instances according to the configured schedule.'
name-en: ACS-ECS-ScheduleToStopInstances
categories:
- time_trigger
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
cron:
Description:
en: 'For more information, see https://www.alibabacloud.com/help/document_detail/169784.html'
Label:
en: CronExpression
Type: String
AssociationProperty: Cron
Default: 0 0 12 ? * *
endDate:
Description:
en: 'Format: yyyy-MM-ddTHH:mm:ssZ.'
Label:
en: EndDate
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: 'YYYY-MM-DDTHH:mm:ssZ'
timeZone:
Label:
en: TimeZone
Type: String
AssociationProperty: TimeZone
Default: UTC
targets:
Type: Json
Label:
en: TargetInstance
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: 'ALIYUN::ECS::Instance'
RegionId: regionId
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: timerTrigger
Action: ACS::TimerTrigger
Description:
en: Triggers a task as scheduled by specifying type and expression
Properties:
Type: cron
Expression: '{{ cron }}'
EndDate: '{{ endDate }}'
TimeZone: '{{ timeZone }}'
- Name: getInstance
Description:
en: Views the 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
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.instanceIds }}'
Outputs:
instanceIds:
Type: List
Value: '{{ getInstance.instanceIds }}'
Metadata:
ALIYUN::OOS::Interface:
ParameterGroups:
- Parameters:
- timeZone
- cron
- endDate
Label:
default:
en: Timer Trigger Configure
- Parameters:
- regionId
- targets
Label:
default:
en: Select ECS Instances
- Parameters:
- rateControl
- OOSAssumeRole
Label:
default:
en: Control Options