Template name
ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances - Schedules the start and stop or restart of RDS instances
Template description
Starts and then stops or stops and then starts ApsaraDB RDS instances as scheduled.
Template type
Automated
Owner
Alibaba Cloud
Input parameters
Parameter | Description | Data type | Required | Default value | Limit |
targets | The destination instances. | Json | Yes | ||
dailyStartTime | The time when the instances are started each day. | String | Yes | ||
dailyStopTime | The time when the instances are stopped each day. | String | Yes | ||
regionId | The region ID. | String | No | {{ ACS::RegionId }} | |
startFirstOrStopFirst | The mode in which the instances are started or stopped. | String | No | StartFirst | |
weekdays | The days of the week to run the task. | String | No | * | |
triggerEndDate | The end time of the scheduled task. | String | No | 2099-12-01T00:00:00Z | |
rateControl | Task execution concurrency rate | Json | No | {'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10} | |
OOSAssumeRole | The RAM role that is assumed by CloudOps Orchestration Service (OOS). | String | No | AliyunServiceRoleForOOSInstanceScheduler |
Output parameters
N/A.
Permission policy that is required to execute the template
{
"Version": "1",
"Statement": [
{
"Action": [
"rds:DescribeDBInstances",
"rds:StartDBInstance",
"rds:StopDBInstance"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"oos:GetApplicationGroup"
],
"Resource": "*",
"Effect": "Allow"
}
]
}
Details
ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances
Template content
FormatVersion: OOS-2019-06-01
Description:
en: Schedule to start and stop RDS instances
name-en: ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances
categories:
- time_trigger
- rds
Parameters:
regionId:
Type: String
Label:
en: RegionId
AssociationProperty: RegionId
Default: '{{ ACS::RegionId }}'
targets:
Type: Json
Label:
en: TargetInstance
AssociationProperty: Targets
AssociationPropertyMetadata:
ResourceType: ALIYUN::RDS::Instance
RegionId: regionId
ChargeType: PostPaid
startFirstOrStopFirst:
Type: String
Label:
en: StartFirstOrStopFirst
AllowedValues:
- StartFirst
- StopFirst
Default: StartFirst
AssociationPropertyMetadata:
LocaleKey: OOSStopInstanceMode
weekdays:
Label:
en: Task execution cycle
Type: String
AssociationProperty: TimeTriggerWeekly
Default: '*'
AssociationPropertyMetadata:
Mode: '${startFirstOrStopFirst}'
StartTime: '${dailyStartTime}'
StopTime: '${dailyStopTime}'
dailyStartTime:
Label:
en: DailyStartTime
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: HH:mm:ssZ
dailyStopTime:
Label:
en: DailyStopTime
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: HH:mm:ssZ
triggerEndDate:
Label:
en: The end date of time trigger
Type: String
AssociationProperty: DateTime
AssociationPropertyMetadata:
Format: YYYY-MM-DDTHH:mm:ssZ
Default: '2099-12-01T00:00:00Z'
rateControl:
Label:
en: RateControl
Type: Json
AssociationProperty: RateControl
Default:
Mode: Concurrency
MaxErrors: 0
Concurrency: 10
OOSAssumeRole:
Label:
en: OOSAssumeRole
Type: String
Default: AliyunServiceRoleForOOSInstanceScheduler
RamRole: '{{ OOSAssumeRole }}'
Conditions:
StartFirst:
Fn::Equals:
- StartFirst
- '{{startFirstOrStopFirst}}'
StopFirst:
Fn::Equals:
- StopFirst
- '{{startFirstOrStopFirst}}'
Tasks:
- Name: timerTrigger
Action: ACS::TimerTrigger
Description:
en: Triggers a task as scheduled by specifying a cron expression
Properties:
Type: cron
EndDate: '{{ triggerEndDate }}'
Expression:
Fn::Join:
- ' '
- - '0'
- Fn::Select:
- 1
- Fn::Split:
- ':'
- Fn::If:
- Fn::Equals:
- StartFirst
- '{{startFirstOrStopFirst}}'
- '{{ dailyStartTime }}'
- '{{ dailyStopTime }}'
- Fn::Select:
- 0
- Fn::Split:
- ':'
- Fn::If:
- Fn::Equals:
- StartFirst
- '{{startFirstOrStopFirst}}'
- '{{ dailyStartTime }}'
- '{{ dailyStopTime }}'
- '?'
- '*'
- '{{ weekdays }}'
- Name: getInstance
Description:
en: Gets the RDS instances
Action: ACS::SelectTargets
Properties:
ResourceType: ALIYUN::RDS::Instance
RegionId: '{{regionId}}'
Filters:
- '{{ targets }}'
- Name: startInstanceFirst
Action: ACS::RDS::StartInstance
Description:
en: Starts the RDS instances first
When: StartFirst
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.Instances.Instance[].InstanceId }}'
- Name: sleepToStopTime
Action: ACS::Sleep
Description:
en: Sleeps until the instance stop time
When: StartFirst
Properties:
Duration:
Fn::DurationBetween:
- '{{ dailyStartTime }}'
- '{{ dailyStopTime }}'
- Name: stopInstanceSecond
Action: ACS::RDS::StopInstance
Description:
en: Stops the RDS instances
When: StartFirst
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.Instances.Instance[].InstanceId }}'
- Name: stopInstanceFirst
Action: ACS::RDS::StopInstance
Description:
en: Stops the RDS instances first
When: StopFirst
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.Instances.Instance[].InstanceId }}'
- Name: sleepToStartTime
Action: ACS::Sleep
Description:
en: Sleeps until the instance start time
When: StopFirst
Properties:
Duration:
Fn::DurationBetween:
- '{{ dailyStopTime }}'
- '{{ dailyStartTime }}'
- Name: startInstance
Action: ACS::RDS::StartInstance
Description:
en: Starts the RDS instances
When: StopFirst
Properties:
regionId: '{{ regionId }}'
instanceId: '{{ ACS::TaskLoopItem }}'
Loop:
RateControl: '{{ rateControl }}'
Items: '{{ getInstance.Instances.Instance[].InstanceId }}'