Purpose
You can use this action to wait for a resource to reach the desired status. By using the OpenAPI of a cloud product to query the status of a specific resource, you can wait until the resource's status matches what you expect. For instance, after creating a resource through the ECS OpenAPI RunInstances
, you can employ ACS::WaitFor
to wait until the instance is fully operational, meaning its status is Running.
Syntax
Tasks:
- Name: waitForTaskExample
Action: ACS::WaitFor
Properties:
# The following properties are consistent with ACS::ExecuteAPI. Please refer to the ACS::ExecuteAPI syntax description.
Service: ECS
API: DescribeInstances
Parameters:
InstanceId: i-12345678abcedfg
# The following properties are specific to ACS::WaitFor
PropertySelector: "jq selector" # Required. The specific API return value to wait for. Refer to the ValueSelector description in ACS::ExecuteAPI.
StopRetryValues: # Optional. Stops task waiting and API retry once the task PropertySelector result is in status1. For example, if status1 is Stopped, once the API return result is filtered to Stopped, the task execution stops.
- status1
DesiredValues: # Either DesiredValue or NotDesiredValues is required. The intercepted value above must match one of the following values. A match indicates success; otherwise, it will timeout and fail.
- value1
- value2
NotDesiredValues: # Either DesiredValue or NotDesiredValues is required. The intercepted value above must not match any of the following values. If none match, it indicates success; otherwise, it will timeout and fail.
- value3
- value4
Retries: # Optional. Indicates the maximum number of retries. The default value is 10. Enter a positive integer, such as 5. The value range is [0,300].
DelayType: # Exponential (default), Constant, Linear. The retry interval for Exponential type is: 2 ^ times (number of retries); the retry interval for Constant type is fixed at Delay; the retry interval for Linear type is: Delay + BackOff * times (number of retries).
Delay: # This property needs to be added when DelayType is Constant or Linear. It indicates the retry interval time. Enter a positive integer, such as 10, indicating a retry interval of 10s. The default value is 2. The value range is [1,3600].
BackOff: # This property needs to be added when DelayType is Linear. It indicates the retry interval compensation time. Enter a positive integer. The default value is 2. The value range is [1,3600].
MaxRetryInterval: # Maximum retry interval in seconds. The default value is 1800. Enter a positive integer. The value range is [1, 1800].
Outputs: # The task where the WaitFor action is located supports output. When the task meets the NotDesiredValues/DesiredValues conditions, the task execution will succeed and return the response parameter.
ValueSelector: # jq selector syntax. Use the OpenAPI return as JSON input. Refer to jq syntax at https://stedolan.github.io/jq
Type: String/Boolean/List(Array)/Number/Object
{
"Tasks": [
{
"Name": "waitForTaskExample",
"Action": "ACS::WaitFor",
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"InstanceId": "i-12345678abcedfg"
},
"PropertySelector": "jq selector",
"StopRetryValues": [
"status1"
],
"DesiredValues": [
"value1",
"value2"
],
"NotDesiredValues": [
"value3",
"value4"
]
},
"Retries": "# Optional. Indicates the maximum number of retries. The default value is 10. Enter a positive integer, such as 5. The value range is [0,300].",
"DelayType": "# Exponential (default), Constant, Linear. The retry interval for Exponential type is: 2 ^ times (number of retries); the retry interval for Constant type is fixed at Delay; the retry interval for Linear type is: Delay + BackOff * times (number of retries).",
"Delay": "# This property needs to be added when DelayType is Constant or Linear. It indicates the retry interval time. Enter a positive integer, such as 10, indicating a retry interval of 10s. The default value is 2. The value range is [1,3600].",
"BackOff": "# This property needs to be added when DelayType is Linear. It indicates the retry interval compensation time. Enter a positive integer. The default value is 2. The value range is [1,3600].",
"MaxRetryInterval": "# Maximum retry interval in seconds. The default value is 1800. Enter a positive integer. The value range is [1, 1800]."
"Outputs": {
"ValueSelector": "# jq selector syntax. Use the OpenAPI return as JSON input. Refer to jq syntax at https://stedolan.github.io/jq",
"Type": "String/Boolean/List(Array)/Number/Object"
}
}
]
}
Sample statement
The following template starts a specified instance and uses ACS::WaitFor to wait until the instance's status becomes 'Running'.
---
FormatVersion: OOS-2019-06-01
Parameters:
InstanceId:
Description: the instance id that you will start.
Type: String
Tasks:
- Name: startInstance
Action: ACS::ExecuteAPI
Description: start instance with specified parameters
Properties:
Service: ECS
API: StartInstance
Parameters:
InstanceId: '{{ InstanceId }}'
- Name: untilInstanceReady
Action: ACS::WaitFor
Description: describe instances with specified parameters
MaxRetryInterval: 900
Properties:
Service: ECS
API: DescribeInstances
Parameters:
InstanceIds:
- '{{ InstanceId }}'
PropertySelector: Instances.Instance[].Status
DesiredValues:
- Running
{
"FormatVersion": "OOS-2019-06-01",
"Parameters": {
"InstanceId": {
"Description": "the instance id that you will start.",
"Type": "String"
}
},
"Tasks": [
{
"Name": "startInstance",
"Action": "ACS::ExecuteAPI",
"Description": "start instance with specified parameters",
"Properties": {
"Service": "ECS",
"API": "StartInstance",
"Parameters": {
"InstanceId": "{{ InstanceId }}"
}
}
},
{
"Name": "untilInstanceReady",
"Action": "ACS::WaitFor",
"Description": "describe instances with specified parameters",
"MaxRetryInterval": 900,
"Properties": {
"Service": "ECS",
"API": "DescribeInstances",
"Parameters": {
"InstanceIds": [ "{{ InstanceId }}"]
},
"PropertySelector": "Instances.Instance[].Status",
"DesiredValues": [ "Running" ]
}
}
]
}