All Products
Search
Document Center

CloudOps Orchestration Service:ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances

Last Updated:Dec 04, 2024

Template name

ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances

Execute Now

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 cycle of the scheduled task.

String

No

*

triggerEndDate

The end time of the scheduled task.

String

No

2099-12-01T00:00:00Z

rateControl

The rate control settings.

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"
        }
    ]
}

References

ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Schedule to start and stop RDS instances   
  name-en: ACS-RDS-ScheduleToStartAndStopOrStopAndStartInstances
  Starts and then stops or stops and then starts ApsaraDB RDS instances as scheduled.
  categories:
    - time_trigger
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
  startFirstOrStopFirst:
    Type: String
    Label:
      en: StartFirstOrStopFirst     
    AllowedValues:
      - StartFirst
      - StopFirst
    Default: StartFirst
    AssociationPropertyMetadata:
      LocaleKey: OOSStopInstanceMode
  weekdays:
    Label:
      en: The Cycle of task      
    Type: String
    AssociationProperty: TimeTriggerWeekly
    Default: '*'
  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 }}'
Tasks:
  - Name: timerTrigger
    Action: ACS::TimerTrigger
    Description:
      en: Triggers a task as scheduled by specifying 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: Get the RDS instances   
    Action: ACS::SelectTargets
    Properties:
      ResourceType: ALIYUN::RDS::Instance
      RegionId: '{{regionId}}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: Instances.Instance[].InstanceId
  - Name: startInstanceFirst
    Action: ACS::RDS::StartInstance
    Description:
      en: Starts the RDS instances  
    When:
      Fn::Equals:
        - StartFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
  - Name: sleepToStopTime
    Action: ACS::Sleep
    Description:
      en: Sleep to instance stop time 
    When:
      Fn::Equals:
        - StartFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      Duration:
        Fn::DurationBetween:
          - '{{ dailyStartTime }}'
          - '{{ dailyStopTime }}'
  - Name: stopInstanceSecond
    Action: ACS::RDS::StopInstance
    Description:
      en: Stops the RDS instances
    When:
      Fn::Equals:
        - StartFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
  - Name: stopInstanceFirst
    Action: ACS::RDS::StopInstance
    Description:
      en: Stop the RDS instances first
    When:
      Fn::Equals:
        - StopFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
  - Name: sleepToStartTime
    Action: ACS::Sleep
    Description:
      en: Sleep to instance stop time
    When:
      Fn::Equals:
        - StopFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      Duration:
        Fn::DurationBetween:
          - '{{ dailyStopTime }}'
          - '{{ dailyStartTime }}'
  - Name: startInstance
    Action: ACS::RDS::StartInstance
    Description:
      en: Starts the RDS instances
    When:
      Fn::Equals:
        - StopFirst
        - '{{startFirstOrStopFirst}}'
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'