All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-ScheduleToStartAndStopOrStopAndStartInstances

Last Updated:Dec 23, 2025

Template name

ACS-ECS-ScheduleToStartAndStopOrStopAndStartInstances

Execute now

Template description

Scheduled startup and shutdown

Template type

Automation

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Constraints

targets

The target instances.

Json

Yes

dailyStartTime

The time to start the instances each day.

String

Yes

dailyStopTime

The time to stop the instances each day.

String

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

startFirstOrStopFirst

The start/stop mode.

String

No

StartFirst

weekdays

The days of the week to run the task.

String

No

*

triggerEndDate

The end time for the trigger.

String

No

2099-12-01T00:00:00Z

stoppedMode

The stop mode.

String

No

KeepCharging

hibernate

Specifies whether to hibernate the instances.

Boolean

No

False

rateControl

The concurrency rate for the task.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 0, '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

ACS-ECS-ScheduleToStartAndStopOrStopAndStartInstances details

Template content

Specifies the stop mode for a pay-as-you-go ECS instance. Valid values:
Description:
  en: Schedules ECS instances to either start then stop, or stop then start.
  zh-cn: Schedules ECS instances to either start then stop, or stop then start.
  name-en: ACS-ECS-ScheduleToStartAndStopOrStopAndStartInstances
  name-zh-cn: Scheduled start and stop or stop and start of instances
  categories:
    - time_trigger
Parameters:
  regionId:
    Type: String
    Label:
      en: Region ID
      zh-cn: Region ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Type: Json
    Label:
      en: Target instance
      zh-cn: Target instance
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
  startFirstOrStopFirst:
    Type: String
    Label:
      en: Start or stop mode
      zh-cn: Start or stop mode
    Description:
      en: 'The scheduled start and stop actions are a single task. If you create this task after its scheduled start time for the day, it will not run on that day.'
      zh-cn: 'The scheduled start and stop actions are a single task. If you create this task after its scheduled start time for the day, it will not run on that day.'
    AllowedValues:
      - StartFirst
      - StopFirst
    Default: StartFirst
    AssociationPropertyMetadata:
      LocaleKey: OOSStopInstanceMode
  weekdays:
    Label:
      en: Task execution cycle
      zh-cn: Task execution cycle
    Type: String
    AssociationProperty: TimeTriggerWeekly
    Default: '*'
    AssociationPropertyMetadata:
      Mode: '${startFirstOrStopFirst}'
      StartTime: '${dailyStartTime}'
      StopTime: '${dailyStopTime}'
  dailyStartTime:
    Label:
      en: Daily start time
      zh-cn: Daily start time
    Type: String
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: HH:mm:ssZ
  dailyStopTime:
    Label:
      en: Daily stop time
      zh-cn: Daily stop time
    Type: String
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: HH:mm:ssZ
  triggerEndDate:
    Label:
      en: Trigger end time
      zh-cn: Trigger end time
    Type: String
    AssociationProperty: DateTime
    AssociationPropertyMetadata:
      Format: YYYY-MM-DDTHH:mm:ssZ
    Default: '2099-12-01T00:00:00Z'
  stoppedMode:
    Label:
      en: Stop mode
      zh-cn: Stop mode
    Description:
      en: <p>The stop mode for pay-as-you-go ECS instances. Value:</p> <ul> <li><code="">StopCharging</code=""></li></ul>
      zh-cn: <p>The stop mode for pay-as-you-go ECS instances. Value:</p> <ul> <li><code="">StopCharging</code=""></li></ul>

to take effect. For more information, see Economical mode for pay-as-you-go instances.

Standard stop mode: The instance continues to be charged after it is stopped.

The stop mode for the pay-as-you-go instance. Valid values are:

FormatVersion: OOS-2019-06-01 Description: en: Starts and then stops, or stops and then starts, Elastic Compute Service (ECS) instances on a schedule. Parameters: regionId: Label: en: Region Description: en: The region where the ECS instances are located. Type: String AssociationProperty: RegionId Default: '{{ ACS::RegionId }}' targets: Label: en: Target Instance Description: en: The ECS instances to operate on. Type: Json AssociationProperty: Targets AssociationPropertyMetadata: ResourceType: ALIYUN::ECS::Instance RegionId: regionId startFirstOrStopFirst: Label: en: Start First or Stop First Description: en: Specifies whether to start the instances first or stop the instances first. Type: String AllowedValues: - StartFirst - StopFirst Default: StartFirst weekdays: Label: en: Weekdays Description: 'en: The days of the week on which to execute the task. You can specify multiple days, separated by commas (,).' Type: String AllowedPattern: '^((([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN),)*([1-7]|MON|TUE|WED|THU|FRI|SAT|SUN)|^\*|^\?)$' Default: 1,2,3,4,5 dailyStartTime: Label: en: Daily Start Time Description: 'en: The time of day to start the instances. Use the HH:mm format. The time is in UTC.' Type: String AllowedPattern: '^([01]?[0-9]|2[0-3]):[0-5][0-9]$' Default: '09:00' dailyStopTime: Label: en: Daily Stop Time Description: 'en: The time of day to stop the instances. Use the HH:mm format. The time is in UTC.' Type: String AllowedPattern: '^([01]?[0-9]|2[0-3]):[0-5][0-9]$' Default: '18:00' triggerEndDate: Label: en: Trigger End Date Description: 'en: The end date of the scheduled task. The time is in UTC.' Type: String AllowedPattern: ^2[0-9]{3}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])T([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]Z$ stoppedMode: Label: en: ECS Stopped Mode Description: 'en: The stop mode for the pay-as-you-go instance. Valid values are StopCharging and KeepCharging. StopCharging: Economical mode. For the conditions required for this mode to take effect, see Economical mode for pay-as-you-go instances. KeepCharging: Standard stop mode. The instance continues to be charged after it is stopped.' Type: String AllowedValues: - StopCharging - KeepCharging Default: KeepCharging AssociationPropertyMetadata: LocaleKey: ECSStoppedMode hibernate: Label: en: Hibernate Instance Type: Boolean Default: false rateControl: Label: en: Rate Control Type: Json AssociationProperty: RateControl Default: Mode: Concurrency MaxErrors: 0 Concurrency: 10 OOSAssumeRole: Label: en: OOS Assume Role Type: String Default: AliyunServiceRoleForOOSInstanceScheduler RamRole: '{{ OOSAssumeRole }}' Tasks: - Name: timerTrigger Action: ACS::TimerTrigger Description: en: Triggers a task on a schedule using 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: Retrieves the specified ECS instances. Action: ACS::SelectTargets Properties: ResourceType: ALIYUN::ECS::Instance RegionId: '{{regionId}}' Filters: - '{{ targets }}' Outputs: instanceIds: Type: List ValueSelector: Instances.Instance[].InstanceId - Name: startInstanceFirst Action: ACS::ECS::StartInstance Description: en: Starts the ECS instances first. When: Fn::Equals: - StartFirst - '{{startFirstOrStopFirst}}' OnError: sleepToStopTime Properties: regionId: '{{ regionId }}' instanceId: '{{ ACS::TaskLoopItem }}' Loop: RateControl: '{{ rateControl }}' Items: '{{ getInstance.instanceIds }}' - Name: sleepToStopTime Action: ACS::Sleep Description: en: Pauses the execution until the specified instance stop time. When: Fn::Equals: - StartFirst - '{{startFirstOrStopFirst}}' Properties: Duration: Fn::DurationBetween: - '{{ dailyStartTime }}' - '{{ dailyStopTime }}' - Name: stopInstanceSecond Action: ACS::ECS::StopInstance Description: en: Stops the ECS instances. When: Fn::Equals: - StartFirst - '{{startFirstOrStopFirst}}' Properties: regionId: '{{ regionId }}' instanceId: '{{ ACS::TaskLoopItem }}' stoppedMode: '{{ stoppedMode }}' hibernate: '{{ hibernate }}' Loop: RateControl: '{{ rateControl }}' Items: '{{ getInstance.instanceIds }}' - Name: stopInstanceFirst Action: ACS::ECS::StopInstance Description: en: Stops the ECS instances first. When: Fn::Equals: - StopFirst - '{{startFirstOrStopFirst}}' OnError: sleepToStartTime Properties: regionId: '{{ regionId }}' instanceId: '{{ ACS::TaskLoopItem }}' stoppedMode: '{{ stoppedMode }}' hibernate: '{{ hibernate }}' Loop: RateControl: '{{ rateControl }}' Items: '{{ getInstance.instanceIds }}' - Name: sleepToStartTime Action: ACS::Sleep Description: en: Pauses the execution until the specified instance start time. When: Fn::Equals: - StopFirst - '{{startFirstOrStopFirst}}' Properties: Duration: Fn::DurationBetween: - '{{ dailyStopTime }}' - '{{ dailyStartTime }}' - Name: startInstance Action: ACS::ECS::StartInstance Description: en: Starts the ECS instances. When: Fn::Equals: - StopFirst - '{{startFirstOrStopFirst}}' Properties: regionId: '{{ regionId }}' instanceId: '{{ ACS::TaskLoopItem }}' Loop: RateControl: '{{ rateControl }}' Items: '{{ getInstance.instanceIds }}'