All Products
Search
Document Center

CloudOps Orchestration Service:ACS::WaitFor

Last Updated:Apr 12, 2023

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

Tasks:
  - Name: waitForTaskExample
    Action: ACS::WaitFor
    Properties: 
      # 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.
      Service: ECS
      API: DescribeInstances
      Parameters: 
        InstanceId: i-12345678abcedfg
      # The following attributes are unique attributes of the ACS::WaitFor action.
      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.
      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.
        - status1
      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.
        - value1
        - value2
      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.
        - value3
        - value4
    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.
    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.
      OutputParameter1:
        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/.
        Type: String/Boolean/List(Array)/Number/Object
  • JSON format (For more information, see the parameter description for the YAML format.)

{
  "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"
        ]
      },
    "Outputs": {
        "OutputParameter1": {
          "ValueSelector": "jq selector",
          "Type": "String/Boolean/List(Array)/Number/Object"
        }
      }
    }
  ]
}

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

---
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
  Properties:
    Service: ECS
    API: DescribeInstances
    Parameters:
      InstanceIds:
      - '{{ InstanceId }}'
    PropertySelector: Instances.Instance[].Status
    DesiredValues:
    - Running
  • JSON format

{
    "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",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeInstances",
                "Parameters": {
                    "InstanceIds": [ "{{ InstanceId }}"]
                },
                "PropertySelector": "Instances.Instance[].Status",
                "DesiredValues": [ "Running" ],
            }
        }
    ]
}