All Products
Search
Document Center

ACS__WaitFor

Last Updated: May 03, 2020

Description

The ACS::WaitFor action is used to wait for the specified resource to enter the expected state after an API operation is called. You can call the API operations of cloud services to query the statuses of specified resources until the resources enter the expected state. For example, after you call the RunInstances operation of Elastic Compute Service (ECS) to create an ECS instance, you can call the ACS::WaitFor action to wait for the ECS instance to enter the Running state, indicating that the ECS instance is created.

Syntax

  1. Tasks:
  2. - Name: waitForTaskExample
  3. Action: ACS::WaitFor
  4. Properties:
  5. # The following attributes are the same as those of the ACS::ExecuteAPI action. For more information, see the syntax description for the ACS::ExecuteAPI action.
  6. Service: ECS
  7. API: DescribeInstances
  8. Parameters:
  9. InstanceId: i-12345678abcedfg
  10. # The following attributes are unique attributes of the ACS::WaitFor action.
  11. PropertySelector: "jq selector" # Required. The jQuery selector for selecting the JSON data to wait for. For more information, see the description of ValueSelector in ACS::ExecuteAPI.
  12. StopRetryValues: # Optional. A task terminates the Waiting state and the API action retries when a specified state is returned. For example, the task stops if the Stopped state is returned.
  13. - status1
  14. DesiredValues: # The expected values. If the value selected by PropertySelector matches one of the expected values, the operation is successful. If the value selected by PropertySelector does not match any of the expected values, the operation times out and fails. This parameter is required if you do not specify the NotDesiredValues parameter.
  15. - value1
  16. - value2
  17. NotDesiredValues: # The values that are not expected. If the value selected by PropertySelector does not match any of the expected values, the operation is successful. If the value selected by PropertySelector matches one of the expected values, the operation times out and fails. This parameter is required if you do not specify the DesiredValues parameter.
  18. - value3
  19. - value4
  20. Retries: times # Optional. The maximum number of retries. The value must be a positive integer, such as 5. The retry interval grows in an exponential manner. The interval is 1 second after the first retry, 2 seconds after the second retry, 4 seconds after the third retry, 8 seconds after the forth retry, and so on.
  21. Outputs: # The output parameters of the task where the ACS::WaitFor action resides. When the task is successfully executed, the output parameter values that meet the NotDesiredValues or DesiredValues condition are returned.
  22. OutputParameter1:
  23. ValueSelector: 'jq selector' # The jQuery selector for selecting the required JSON data. For example, when you call an API operation for a task, the jQuery selector extracts the required information from the returned JSON data. For more information, see https://stedolan.github.io/jq/.
  24. Type: String/Boolean/List(Array)/Number/Object
  • JSON format (For more information, see the parameter description for the YAML format.)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "waitForTaskExample",
  5. "Action": "ACS::WaitFor",
  6. "Properties": {
  7. "Service": "ECS",
  8. "API": "DescribeInstances",
  9. "Parameters": {
  10. "InstanceId": "i-12345678abcedfg"
  11. },
  12. "PropertySelector": "jq selector",
  13. "StopRetryValues":["status1"],
  14. "DesiredValues": [
  15. "value1",
  16. "value2"
  17. ],
  18. "NotDesiredValues": [
  19. "value3",
  20. "value4"
  21. ]
  22. },
  23. "Outputs": {
  24. "OutputParameter1": {
  25. "ValueSelector": "jq selector",
  26. "Type": "String/Boolean/List(Array)/Number/Object"
  27. }
  28. }
  29. }
  30. ]
  31. }

Sample code

The following sample code is used to start an instance and call the ACS::WaitFor action to wait for the instance to enter the Running state:

  • YAML format
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Parameters:
  4. InstanceId:
  5. Description: the instance id that you will start.
  6. Type: String
  7. Tasks:
  8. - Name: startInstance
  9. Action: ACS::ExecuteAPI
  10. Description: start instance with specified parameters
  11. Properties:
  12. Service: ECS
  13. API: StartInstance
  14. Parameters:
  15. InstanceId: '{{ InstanceId }}'
  16. - Name: untilInstanceReady
  17. Action: ACS::WaitFor
  18. Description: describe instances with specified parameters
  19. Properties:
  20. Service: ECS
  21. API: DescribeInstances
  22. Parameters:
  23. InstanceIds:
  24. - '{{ InstanceId }}'
  25. PropertySelector: Instances.Instance[].Status
  26. DesiredValues:
  27. - Running
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Parameters": {
  4. "InstanceId": {
  5. "Description": "the instance id that you will start.",
  6. "Type": "String"
  7. }
  8. },
  9. "Tasks": [
  10. {
  11. "Name": "startInstance",
  12. "Action": "ACS::ExecuteAPI",
  13. "Description": "start instance with specified parameters",
  14. "Properties": {
  15. "Service": "ECS",
  16. "API": "StartInstance",
  17. "Parameters": {
  18. "InstanceId": "{{ InstanceId }}"
  19. }
  20. }
  21. },
  22. {
  23. "Name": "untilInstanceReady",
  24. "Action": "ACS::WaitFor",
  25. "Description": "describe instances with specified parameters",
  26. "Properties": {
  27. "Service": "ECS",
  28. "API": "DescribeInstances",
  29. "Parameters": {
  30. "InstanceIds": [ "{{ InstanceId }}"]
  31. },
  32. "PropertySelector": "Instances.Instance[].Status",
  33. "DesiredValues": [ "Running" ],
  34. }
  35. }
  36. ]
  37. }