As the minimum unit of operations, an action defines a specific operation.
Action types
Actions can be divided 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
The name of an action is in the following format: ACS::<name>
.
Common attributes
Unless otherwise specified, each action has the following attributes:
---
Tasks:
- Name: task_name_1
Action: 'Action'
Description: describe the purpose of the task
OnError: ''ACS::END/<other-task-name>' # The process to be executed if an error occurs when the task is executed. Default value: ACS::END, which indicates that the execution will end when an error occurs.
OnSuccess: 'ACS::NEXT/<other-task-name>/ACS::END' # The process to be executed when the task is successfully executed. Default value: ACS::NEXT, which indicates that the next task is executed after the current task is successfully executed.
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 of the task. The value must be an atom action or a cloud product action. The action name 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
: The task is ended if an error occurs. This is the default value.OnSuccess:ACS::NEXT
: The next task is executed after the current task is successfully executed. This is the default value.OnError: <task_name>
: The specified task is executed if an error occurs when the current task is executed.OnSuccess: <task_name>
: The specified task is executed after the current task is successfully executed.
Example
The following template is used to create a Cloud Assistant command that is run 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. If you want to declare multiple output items, separate them with commas (,). For more information, see the syntax in the following example.
Example
The following template is used to obtain 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. The unique identifier of the output item in the template, such as InstanceIds in the example.
Type
Required. The type of the output item, such as String
and List
.
ValueSelector
Required. The attribute value returned after the template is executed. You can specify the value by using a jQuery selector, such as .Instances or .Instances.Instance[].Status.