全部产品
Search
文档中心

运维编排服务:Action通用属性

更新时间:Dec 01, 2022

动作(Action)定义了一个具体的操作,是操作的最小单位。

动作类型

动作分为以下几种类型:

  • 原子动作(Atom Action)

    • API动作(API Action)

    • 触发器动作(Trigger Action)

    • 控制类动作(Control Action)

    • 嵌套类动作(ACS::Template)

  • 云产品动作(Cloud Product Action)

    • 弹性计算(ECS)类

    • 关系型数据库(RDS)类

    • 钉钉(DingTalk)类

名称格式

动作(Action)的名称格式为ACS::<name>

通用属性

除非某个Action有特殊说明,否则每个Action都具有以下通用属性。

---
Tasks:
  - Name: task_name_1
    Action: 'Action类型'
    Description: describe the purpose of the task
    OnError: 'ACS::END/<other-task-name>' # 默认ACS::END
    OnSuccess: 'ACS::NEXT/<other-task-name>/ACS::END' # 默认ACS::NEXT 
    Properties:
      Service: ECS/RDS/RAM
      API: DeleteInstance/CreateDBInstance/CreateRamRole
      Parameters:
        InstanceId: "i-XXX"
    Outputs:
      Output_parameter_name_1:
        Type: String/List
        ValueSelector": ".Key1"

Action通用定义

  • Name:合法字符为:[a-zA-Z0-9-_],长度限制200个内,不允许包含冒号(:)。

  • Action:必须为以下类型之一,原子action,云产品动作。以ACS::开头。

  • Description:描述当前task的用途。

  • Properties:详细信息,请参见ACS::ExecuteAPI

流程控制类

  • OnError:ACS::END:默认,此任务出错时,中断执行。

  • OnSuccess:ACS::NEXT:默认,此任务成功时,后续如有任务,继续向后执行。

  • OnError: <task_name>:此任务出错时执行指定的任务。

  • OnSuccess: <task_name>:此任务成功时执行指定的任务。

示例

如下模板:执行云助手命令。

  • YAML格式:

FormatVersion: OOS-2019-06-01
Description: Creates a cloud assistant command and triggers it on one ECS instance.
Parameters:
  regionId:
    Description: The ID of region.
    Type: String
    Default: '{{ ACS::RegionId }}'
  commandContent:
    Description: The content of command.
    Type: String
  instanceId:
    Description: The ID of ECS instance that will invoke command.
    Type: String
    MinLength: 1
    MaxLength: 30
  commandType:
    Description: The type of command.
    Type: String
    AllowedValues:
    - RunBatScript
    - RunPowerShellScript
    - RunShellScript
  workingDir:
    Description: The directory where the created command runs on the ECS instances.
    Type: String
    Default: ""
  timeout:
    Description: The value of the invocation timeout period of a command on ECS instances.
    Type: Number
    Default: 600
Tasks:
- Name: runCommand
  Action: 'ACS::ExecuteAPI'
  Description: Executes a cloud assistant command.
  Properties:
    Service: ECS
    API: RunCommand
    Parameters:
      RegionId: '{{ regionId }}'
      CommandContent: '{{ commandContent }}'
      InstanceIds:
        - '{{instanceId}}'
      Name: '{{ ACS::ExecutionId }}'
      Type: '{{ commandType }}'
      WorkingDir: '{{ workingDir }}'
      Timeout: '{{ timeout }}'
  Outputs:
    invokeId:
      Type: String
      ValueSelector: InvokeId
- Name: untilInvocationReady
  Action: ACS::WaitFor
  Description: Waits for the command to be completed.
  OnError: ACS::END
  Retries: 20
  Properties:
    Service: ECS
    API: DescribeInvocations
    Parameters:
      RegionId: '{{ regionId }}'
      InvokeId: '{{ runCommand.invokeId }}'
    DesiredValues:
    - Finished
    StopRetryValues:
    - Failed
    PropertySelector: Invocations.Invocation[].InvokeStatus
- Name: describeInvocationResults
  Action: ACS::ExecuteAPI
  Description: Views the command output of a cloud assistant command in the specified ECS
    instance.
  Properties:
    Service: ECS
    API: DescribeInvocationResults
    Parameters:
      RegionId: '{{ regionId }}'
      InvokeId: '{{ runCommand.invokeId }}'
  Outputs:
    invocationResult:
      Type: String
      ValueSelector: 'Invocation.InvocationResults.InvocationResult[].Output'
- Name: checkInvocationResult
  Action: 'ACS::CheckFor'
  Description: Check the command exitcode of a cloud assistant command.
  OnError: 'ACS::END'
  Properties:
    Service: ECS
    API: DescribeInvocationResults
    Parameters:
      RegionId: '{{ regionId }}'
      InvokeId: '{{ runCommand.InvokeId }}'
    PropertySelector: 'Invocation.InvocationResults.InvocationResult[].ExitCode'
    DesiredValues:
      - 0
Outputs:
  invocationOutput:
    Type: String
    Value:
      'Fn::Base64Decode': '{{ describeInvocationResults.invocationResult }}'
  • JSON格式:

{
  "FormatVersion": "OOS-2019-06-01",
  "Description": "Creates a cloud assistant command and triggers it on one ECS instance.",
  "Parameters": {
    "regionId": {
      "Description": "The ID of region.",
      "Type": "String",
      "Default": "{{ ACS::RegionId }}"
    },
    "commandContent": {
      "Description": "The content of command.",
      "Type": "String"
    },
    "instanceId": {
      "Description": "The ID of ECS instance that will invoke command.",
      "Type": "String",
      "MinLength": 1,
      "MaxLength": 30
    },
    "commandType": {
      "Description": "The type of command.",
      "Type": "String",
      "AllowedValues": [
        "RunBatScript",
        "RunPowerShellScript",
        "RunShellScript"
      ]
    },
    "workingDir": {
      "Description": "The directory where the created command runs on the ECS instances.",
      "Type": "String",
      "Default": ""
    },
    "timeout": {
      "Description": "The value of the invocation timeout period of a command on ECS instances.",
      "Type": "Number",
      "Default": 600
    }
  },
  "Tasks": [
    {
      "Name": "runCommand",
      "Action": "ACS::ExecuteAPI",
      "Description": "Executes a cloud assistant command.",
      "Properties": {
        "Service": "ECS",
        "API": "RunCommand",
        "Parameters": {
          "RegionId": "{{ regionId }}",
          "CommandContent": "{{ commandContent }}",
          "InstanceIds": [
            "{{instanceId}}"
          ],
          "Name": "{{ ACS::ExecutionId }}",
          "Type": "{{ commandType }}",
          "WorkingDir": "{{ workingDir }}",
          "Timeout": "{{ timeout }}"
        }
      },
      "Outputs": {
        "invokeId": {
          "Type": "String",
          "ValueSelector": "InvokeId"
        }
      }
    },
    {
      "Name": "untilInvocationReady",
      "Action": "ACS::WaitFor",
      "Description": "Waits for the command to be completed.",
      "OnError": "ACS::END",
      "Retries": 20,
      "Properties": {
        "Service": "ECS",
        "API": "DescribeInvocations",
        "Parameters": {
          "RegionId": "{{ regionId }}",
          "InvokeId": "{{ runCommand.invokeId }}"
        },
        "DesiredValues": [
          "Finished"
        ],
        "StopRetryValues": [
          "Failed"
        ],
        "PropertySelector": "Invocations.Invocation[].InvokeStatus"
      }
    },
    {
      "Name": "describeInvocationResults",
      "Action": "ACS::ExecuteAPI",
      "Description": "Views the command output of a cloud assistant command in the specified ECS instance.",
      "Properties": {
        "Service": "ECS",
        "API": "DescribeInvocationResults",
        "Parameters": {
          "RegionId": "{{ regionId }}",
          "InvokeId": "{{ runCommand.invokeId }}"
        }
      },
      "Outputs": {
        "invocationResult": {
          "Type": "String",
          "ValueSelector": "Invocation.InvocationResults.InvocationResult[].Output"
        }
      }
    },
    {
      "Name": "checkInvocationResult",
      "Action": "ACS::CheckFor",
      "Description": "Check the command exitcode of a cloud assistant command.",
      "OnError": "ACS::END",
      "Properties": {
        "Service": "ECS",
        "API": "DescribeInvocationResults",
        "Parameters": {
          "RegionId": "{{ regionId }}",
          "InvokeId": "{{ runCommand.InvokeId }}"
        },
        "PropertySelector": "Invocation.InvocationResults.InvocationResult[].ExitCode",
        "DesiredValues": [
          0
        ]
      }
    }
  ],
  "Outputs": {
    "invocationOutput": {
      "Type": "String",
      "Value": {
        "Fn::Base64Decode": "{{ describeInvocationResults.invocationResult }}"
      }
    }
  }
}

任务输出

Task级别的Outputs由输出Type和输出ValueSelector组成。如果声明多个输出项,则用逗号分隔开。请参见下列示例的语法结构。

示例

如下模板:获取指定状态的所有ECS实例。

  • YAML格式:

FormatVersion: OOS-2019-06-01
Description: Views the ECS instances by specifying instance status.
Parameters:
  regionId:
    Description: The ID of region.
    Type: String
    Default: '{{ ACS::RegionId }}'
  status:
    Description: The ECS instances status for query instances.
    Type: String
Tasks:
- Name: describeInstances
  Action: ACS::ExecuteAPI
  Description: Views the ECS instances by specifying instance status.
  Properties:
    Service: ECS
    API: DescribeInstances
    Parameters:
      RegionId: '{{ regionId }}'
      Status: '{{ status }}'
  Outputs:
    instanceIds:
      Type: List
      ValueSelector: Instances.Instance[].InstanceId
Outputs:
  instanceIds:
    Type: List
    Value: '{{ describeInstances.instanceIds }}'
			
  • Json格式:

{  "FormatVersion": "OOS-2019-06-01",  "Description": "Views the ECS instances by specifying instance status.",  "Parameters": {    "regionId": {      "Description": "The ID of region.",      "Type": "String",      "Default": "{{ ACS::RegionId }}"    },    "status": {      "Description": "The ECS instances status for query instances.",      "Type": "String"    }  },  "Tasks": [    {      "Name": "describeInstances",      "Action": "ACS::ExecuteAPI",      "Description": "Views the ECS instances by specifying instance status.",      "Properties": {        "Service": "ECS",        "API": "DescribeInstances",        "Parameters": {          "RegionId": "{{ regionId }}",          "Status": "{{ status }}"        }      },      "Outputs": {        "instanceIds": {          "Type": "List",          "ValueSelector": "Instances.Instance[].InstanceId"        }      }    }  ],  "Outputs": {    "instanceIds": {      "Type": "List",      "Value": "{{ describeInstances.instanceIds }}"    }  }}

输出名称(必需)

输出项的标识符,在模板中具有唯一性。如示例中的InstanceIds。

Type(必需)

输出项的类型,如StringList等。

ValueSelector(必需)

在任务调用API执行完成时,将输出的属性值。支持JQ selector,对于该API返回值,如".Instances",".Instances.Instance[].Status"。