動作(Action)定義了一個具體的操作,是操作的最小單位。
動作類型
動作分為以下幾種類型:
原子動作(Atom Action)
API動作(API Action)
觸發器動作(Trigger Action)
控制類動作(Control Action)
嵌套類動作(ACS::Template)
云產品動作(Cloud Product Action)
彈性計算(ECS)類
關系型數據庫(RDS)類
函數計算(FC)類
釘釘(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::NEXT' # 默認ACS::END
OnSuccess: 'ACS::NEXT/<other-task-name>/ACS::END' # 默認ACS::NEXT
IsCritical: true/false # 默認true
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::END
:此任務成功時,結束執行。OnError:ACS::NEXT
:此任務失敗時,后續如有任務,繼續向后執行。OnSuccess:ACS::NEXT
:默認,此任務成功時,后續如有任務,繼續向后執行。OnError: <task_name>
:此任務出錯時執行指定的任務。OnSuccess: <task_name>
:此任務成功時執行指定的任務。IsCritical
:將一個任務指定為成功完成自動化的關鍵步驟,該選項的默認值為 true。此屬性只會影響最終執行的狀態,若您在某個Action中配置“IsCritical:false”,則即使此Action執行失敗,最終整體的執行狀態仍然會顯示為“成功”。
示例
如下模板:執行云助手命令。
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(必需)
輸出項的類型,如String
、List
等。
ValueSelector(必需)
在任務調用API執行完成時,將輸出的屬性值。支持JQ selector,對于該API返回值,如".Instances",".Instances.Instance[].Status"。