All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-ScheduleToAcceptInquiredSystemEvent

Last Updated:Nov 25, 2024

Template name

ACS-ECS-ScheduleToAcceptInquiredSystemEvent

Execute Now

Template description

Accepts the default operation for a system event and authorizes the system to perform the default operation as scheduled. Procedure:

  1. Stop an Elastic Compute Service (ECS) instance.

  2. Accept the default operation for a system event and authorize the system to perform the default operation.

  3. Start the ECS instance.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

timerTrigger

The type of the scheduled task.

Json

Yes

instanceId

The ID of the ECS instance.

String

Yes

eventId

The ID of a system event.

String

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

AliyunServiceRoleForOOSSystemEventOperator

Output parameters

None

Permission policy that is required to execute the template

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

References

For more information, see ACS-ECS-ScheduleToAcceptInquiredSystemEvent.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: <p>Regularly accept and authorize the execution of system event operations. Template process: <ol><li>Stop ECS instance</li><li>Accept inquired system event</li><li>Start ECS instance</li</ol></p>
  zh-cn: the description in Chinese  
  name-en: ACS-ECS-ScheduleToAcceptInquiredSystemEvent
  name-zh-cn: the description in Chinese
  categories:
    - time_trigger
Parameters:
  timerTrigger:
    Type: Json
    Label:
      en: TimerTrigger
      zh-cn: the description in Chinese
    AssociationProperty: ALIYUN::OOS::Component::TimerTrigger
    AssociationPropertyMetadata:
      MinuteInterval: 30
  regionId:
    Label:
      en: RegionId
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  instanceId:
    Label:
      en: ECSInstanceId
      zh-cn: the description in Chinese
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    AssociationPropertyMetadata:
      RegionId: regionId
  eventId:
    Label:
      en: EventId
      zh-cn: the description in Chinese
    Type: String
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: the description in Chinese
    Type: String
    Default: AliyunServiceRoleForOOSSystemEventOperator
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: timerTrigger
    Action: ACS::TimerTrigger
    Description:
      en: Triggers a task as scheduled by specifying type and expression
      zh-cn: the description in Chinese
    Properties:
      Type:
        Fn::Select:
          - type
          - '{{timerTrigger}}'
      Expression:
        Fn::Select:
          - expression
          - '{{timerTrigger}}'
      EndDate:
        Fn::Select:
          - endDate
          - '{{ timerTrigger }}'
      TimeZone:
        Fn::Select:
          - timeZone
          - '{{ timerTrigger }}'
  - Name: getInstance
    Action: ACS::SelectTargets
    Description:
      en: Views the ECS instances
      zh-cn: the description in Chinese
    Properties:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: '{{ regionId }}'
      Filters:
        - Type: ResourceIds
          RegionId: '{{ regionId }}'
          ResourceIds:
            - '{{ instanceId }}'
    Outputs:
      instanceId:
        Type: String
        ValueSelector: Instances.Instance[].InstanceId
      status:
        Type: String
        ValueSelector: Instances.Instance[].Status
  - Name: checkForWhetherResourceExist
    Action: ACS::Choice
    Description:
      en: Check whether the resource exist
      zh-cn: the description in Chinese
    Properties:
      DefaultTask: stopInstance
      Choices:
        - When:
            Fn::Equals:
              - Null
              - '{{ getInstance.instanceId }}'
          NextTask: ACS::END
  - Name: stopInstance
    Action: ACS::ECS::StopInstance
    Description:
      en: Stops the ECS instances
      zh-cn: the description in Chinese
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ getInstance.instanceId }}'
  - Name: acceptInquiredSystemEvent
    Action: ACS::ExecuteApi
    Description:
      en: Accept and authorize system event actions
      zh-cn: the description in Chinese
    Properties:
      Service: ECS
      API: AcceptInquiredSystemEvent
      Parameters:
        RegionId: '{{ regionId }}'
        EventId: '{{ eventId }}'
  - Name: startInstance
    Action: ACS::ECS::StartInstance
    When:
      Fn::Equals:
        - Running
        - '{{ getInstance.status }}'
    Description:
      en: Starts the ECS instances
      zh-cn: the description in Chinese
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ getInstance.instanceId }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - timerTrigger
        Label:
          default:
            zh-cn: the description in Chinese
            en: The Timer Trigger
      - Parameters:
          - regionId
          - instanceId
          - eventId
        Label:
          default:
            zh-cn: the description in Chinese
            en: Select ECS Instances
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            zh-cn: the description in Chinese
            en: Control Options