Common action properties

Updated at:

An action is the smallest unit of operation in a template and defines a specific task to perform.

Action types

Actions fall into the following types:

  • Atom actions:

    • API actions

    • Trigger actions

    • Control actions

    • Embedded actions

  • Cloud product actions

    • Elastic Compute Service (ECS) actions

    • ApsaraDB RDS actions

    • Function Compute actions

    • DingTalk actions

Name format

Action names use the format ACS::<name>.

Common attributes

Unless otherwise specified, every action supports the following attributes:

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

Basic attributes

  • Name: the name of the task. The name can contain letters, digits, underscores (_), and hyphens (-). It can be up to 200 characters in length, and cannot contain colons (:).

  • Action: the action to perform. The value must be an atom action or a cloud product action and must start with ACS::.

  • Description: the purpose of the task.

  • Properties: the properties of the task. For more information, see ACS::ExecuteAPI.

Process control attributes

  • OnError: ACS::END: (Default) Ends the execution if the task fails.

  • OnCancel: ACS::END: (Default) Ends the execution if the task is canceled.

  • OnSuccess: ACS::END: Ends the execution after the task succeeds.

  • OnError: ACS::NEXT: Continues to the next task if the task fails.

  • OnCancel: ACS::NEXT: Continues to the next task if the task is canceled.

  • OnSuccess: ACS::NEXT: (Default) Continues to the next task after the task succeeds.

  • OnError: <task_name>: Executes the specified task if the current task fails.

  • OnCancel: <task_name>: Executes the specified task if the current task is canceled.

  • OnSuccess: <task_name>: Executes the specified task after the current task succeeds.

  • IsCritical: specifies whether the task is critical for the automation to succeed. The default value is true. This property affects only the final execution status. If you set IsCritical to false for an action, the overall execution is marked as successful even if that action fails.

  • When: conditionally runs the current task based on specified criteria.

Example

The following template creates a Cloud Assistant command and runs it on an ECS instance.

  • YAML format

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 format

{
  "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 output attributes

Task output attributes include Type and ValueSelector. To declare multiple output items, separate them with commas (,). See the following example for syntax details.

Example

The following template retrieves all ECS instances in the specified state.

  • YAML format

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 format

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

Output item name

Required. A unique identifier for the output item in the template, such as InstanceIds in the preceding example.

Type

The data type of the output parameter, such as String or List.

ValueSelector

A JQ selector used to extract a value from the action's API response. Examples: .Instances or .Instances.Instance[].Status.