Tous les produits
Search
Centre de documentation

CloudOps Orchestration Service:ACS-ECS-ScheduleToStartAndStopInstances

Dernière mise à jour :Aug 11, 2026

Nom du modèle

ACS-ECS-ScheduleToStartAndStopInstances - Planifiez le démarrage et l'arrêt des instances ECS

Execute Now

Description du modèle

Démarre et arrête les instances ECS selon un planning défini. Utilisez ce modèle pour automatiser la maintenance et optimiser les coûts des environnements de développement. Spécifiez la région (regionId), l'heure de démarrage quotidienne (dailyStartTime), l'heure d'arrêt quotidienne (dailyStopTime) et les jours de la semaine (weekdays) pour définir le calendrier d'exécution.

Type de modèle

Automatisé

Propriétaire

Alibaba Cloud

Paramètres d'entrée

Paramètre

Description

Type

Obligatoire

Valeur par défaut

Limite

dailyStartTime

Heure de démarrage quotidienne des instances ECS.

String

Oui

dailyStopTime

Heure d'arrêt quotidienne des instances ECS.

String

Oui

targets

Instances ECS cibles.

Json

Oui

regionId

Région des instances ECS.

String

Non

{{ ACS::RegionId }}

weekdays

Jours de la semaine d'exécution du planning.

String

Non

MON-FRI

triggerEndDate

Date de fin de la tâche planifiée.

String

Non

2099-12-01T00:00:00Z

stoppedMode

Facturation des instances arrêtées

String

Non

""

hibernate

Mise en veille prolongée des instances ECS.

Boolean

Non

False

rateControl

Concurrence d'exécution des tâches

Json

Non

{'Mode': 'Concurrency', 'MaxErrors': '100%', 'Concurrency': 10}

OOSAssumeRole

Rôle Resource Access Management (RAM) assumé par OOS.

String

Non

AliyunServiceRoleForOOSInstanceScheduler

Paramètres de sortie

Aucun

Autorisations requises

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:StartInstance",
                "ecs:StopInstance"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:GetApplicationGroup"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Détails

Consultez le code source du modèle sur GitHub à l'adresse ACS-ECS-ScheduleToStartAndStopInstances.

Contenu du modèle

FormatVersion: OOS-2019-06-01
Description:
  en: 'Schedule to start and stop ECS instances, applicable to scenarios where regular and scheduled management of ECS instances is required, such as automated operations of development environments and cost optimization. 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 Start Time (dailyStartTime), Daily Stop Time (dailyStopTime), and the Days of Week (weekdays), which define the schedule for the tasks. Upon execution, the template will start and stop the ECS instances according to the configured schedule.'
  zh-cn: 'Schedule to start and stop ECS instances, applicable to scenarios where regular and scheduled management of ECS instances is required, such as automated operations of development environments and cost optimization. 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 Start Time (dailyStartTime), Daily Stop Time (dailyStopTime), and the Days of Week (weekdays), which define the schedule for the tasks. Upon execution, the template will start and stop the ECS instances according to the configured schedule.'
  name-en: ACS-ECS-ScheduleToStartAndStopInstances
  name-zh-cn: Schedule to Start and Stop ECS Instances
  categories:
    - time_trigger
Parameters:
  regionId:
    Type: String
    Label:
      en: Region ID
      zh-cn: Region ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  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'
  weekdays:
    Label:
      en: Weekdays
      zh-cn: Weekdays
    Description:
      en: '* indicates daily, MON indicates Monday only, and MON-FRI indicates Monday to Friday. For more information, see https://www.alibabacloud.com/help/document_detail/169784.html'
      zh-cn: '* indicates daily, MON indicates Monday only, and 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: Trigger end date
      zh-cn: Trigger end date
    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: Target instance
      zh-cn: Target instance
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: regionId
  stoppedMode:
    Label:
      en: Stopped mode
      zh-cn: Stopped mode
    Description:
      en: Specifies whether to continue billing for a pay-as-you-go ECS instance 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: Hibernate instance
      zh-cn: Hibernate instance
    Type: Boolean
    Default: false
  rateControl:
    Label:
      en: Rate control
      zh-cn: Rate control
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 100%
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOSAssumeRole
    Type: String
    Default: AliyunServiceRoleForOOSInstanceScheduler
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: timerTrigger
    Action: 'ACS::TimerTrigger'
    Description:
      en: Triggers a task as scheduled by specifying a cron expression.
      zh-cn: Triggers a task as scheduled by specifying a cron expression.
    Properties:
      Type: cron
      EndDate: '{{ triggerEndDate }}'
      Expression:
        'Fn::Join':
          - ' '
          - - '0'
            - 'Fn::Select':
                - 1
                - 'Fn::Split':
                    - ':'
                    - '{{ dailyStartTime }}'
            - 'Fn::Select':
                - 0
                - 'Fn::Split':
                    - ':'
                    - '{{ dailyStartTime }}'
            - '?'
            - '*'
            - '{{ weekdays }}'
  - Name: getInstance
    Description:
      en: Gets the ECS instances.
      zh-cn: Gets the ECS instances.
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      RegionId: '{{regionId}}'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: startInstance
    Action: 'ACS::ECS::StartInstance'
    Description:
      en: Starts the ECS instances.
      zh-cn: Starts the ECS instances.
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'
  - Name: sleepToSpecifiedTime
    Description:
      en: Sleeps until the instance stop time.
      zh-cn: Sleeps until the instance stop time.
    Action: 'ACS::Sleep'
    Properties:
      Duration:
        'Fn::DurationBetween':
          - '{{ dailyStartTime }}'
          - '{{ dailyStopTime }}'
  - Name: stopInstance
    Action: 'ACS::ECS::StopInstance'
    Description:
      en: Stops the ECS instances.
      zh-cn: Stops the ECS instances.
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
      stoppedMode: '{{ stoppedMode }}'
      hibernate: '{{ hibernate }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'