Tous les produits
Search
Centre de documentation

CloudOps Orchestration Service:ACS::CheckFor

Dernière mise à jour :Aug 11, 2026

Description

L'action ACS::CheckFor vérifie si les ressources cloud se trouvent dans l'état attendu. Si les ressources sont dans l'état spécifié, la tâche aboutit. Dans le cas contraire, elle échoue. Cette action sert généralement aux précontrôles. Par exemple, avant d'arrêter une instance Elastic Compute Service (ECS), utilisez cette action pour vérifier que l'instance est dans l'état Running.

Syntaxe

Tous les attributs de l'action ACS::CheckFor sont identiques à ceux de l'action ACS::WaitFor, sauf l'attribut Action défini sur ACS::CheckFor. Pour plus d'informations, consultez la description de la syntaxe de l'action ACS::WaitFor.

Tasks:
  - Name: checkForTaskExample
    Action: ACS::CheckFor
    Properties: 
      # The following attributes are the same as those of the ACS::ExecuteAPI action. For more information, see the syntax description of the ACS::ExecuteAPI action. 
      Service: ECS
      API: DescribeInstances
      Parameters: 
        InstanceId: i-12345678abcedfg
      # The following attributes are specific to the ACS::CheckFor action:
      PropertySelector: "jq selector" # Required. The selector for selecting the API result to wait for. In this example, a jQuery selector is used. For more information, see the description of the ValueSelector attribute in the ACS::ExecuteAPI action.
      DesiredValues: # The expected values. If the value selected by the PropertySelector attribute matches one of the specified values of the DesiredValues attribute, the task is successful. If the value selected by the PropertySelector attribute does not match any of the specified values of the DesiredValues attribute, the task times out and fails. You must specify one of the DesiredValues and NotDesiredValues attributes. 
        - value1
        - value2
      NotDesiredValues: # The values that are not expected. If the value selected by the PropertySelector attribute does not match any of the specified values of the NotDesiredValues attribute, the task is successful. If the value selected by the PropertySelector attribute matches one of the specified values of the NotDesiredValues attribute, the task times out and fails. You must specify one of the DesiredValues and NotDesiredValues attributes. 
        - value3
        - value4
    Outputs: # The output parameters of the task in which the ACS::CheckFor action resides. If the NotDesiredValues or DesiredValues condition is met, the task is successful, and the output parameters are returned. 
      OutputParameter1: 
        ValueSelector: 'jq selector' # The jQuery selector for selecting the data to return. The jQuery selector extracts information from the JSON data returned by the API operation. For more information about the jq syntax, visit https://stedolan.github.io/jq/.
        Type: String/Boolean/List(Array)/Number/Object
{
    "Tasks": [
        {
            "Name": "checkForTaskExample",
            "Action": "ACS::CheckFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeInstances",
                "Parameters": {
                    "InstanceId": "i-12345678abcedfg"
                },
                "PropertySelector": "jq selector",
                "DesiredValues": [
                    "value1",
                    "value2"
                ],
                "NotDesiredValues": [
                    "value3",
                    "value4"
                                    ]
                          }, 
		"Outputs": {
        "OutputParameter1": {
          "ValueSelector": "jq selector",
          "Type": "String/Boolean/List(Array)/Number/Object"
        }
      }
        }
            ]
}

Exemples

L'exemple suivant montre comment créer un snapshot pour un disque donné. L'action ACS::CheckFor vérifie d'abord que l'instance ECS spécifiée est dans l'état Running ou Stopped.

FormatVersion: OOS-2019-06-01
Parameters:
  DiskId:
    Description: the disk id of the snap shot to copy 
    Type: String
  InstanceId:
    Description: the instances id  of the snap shot to copy 
    Type: String
  SnapshotName:
    Description: snap shot name of the new snap
    Type: String
Tasks:
- Name: checkInstanceReady
	Action: ACS::CheckFor
  Properties:
  	Service: ECS
    API: DescribeInstances
    DesiredValues:
    - Running
    - Stopped
    Parameters:
      InstanceIds:
      - '{{ InstanceId }} '
    PropertySelector: Instances.Instance[].Status
- Name: createSnapshot
	Action: ACS::ExecuteAPI
  Properties:
  	Service: ECS
    API: CreateSnapshot
    Parameters:
      DiskId: '{{ DiskId }}'
      SnapshotName: '{{ SnapshotName }}'
		Outputs:
      SnapshotId:
        Type: String
        ValueSelector: SnapshotId
- Name: waitSnapshotsReady
	Action: ACS::WaitFor
  Properties:
  	Service: ECS
    API: DescribeSnapshots
    DesiredValues:
    - accomplished
    Parameters:
      SnapshotIds:
      - '{{ createSnapshot.SnapshotId }}'
    PropertySelector: Snapshots.Snapshot[].Status
Outputs:
  SnapshotId:
    Type: String
    Value: '{{ createSnapshot.SnapshotId }}'
{
    "FormatVersion": "OOS-2019-06-01",
    "Parameters": {
        "DiskId": {
            "Description": "the disk id of the snap shot to copy ",
            "Type": "String"
        },
        "InstanceId": {
            "Description": "the instances id  of the snap shot to copy ",
            "Type": "String"
        },
        "SnapshotName": {
            "Description": "snap shot name of the new snap",
            "Type": "String"
        }
    },
    "Tasks": [
        {   
            "Name": "checkInstanceReady",
            "Action": "ACS::CheckFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeInstances",
                "DesiredValues": ["Running", "Stopped"],
                "Parameters": {
                    "InstanceIds": ["{{ InstanceId }} "]
                },
                "PropertySelector": "Instances.Instance[].Status"
            }
        },
        {   
            "Name": "createSnapshot",
            "Action": "ACS::ExecuteAPI",
            "Properties": {
                "Service": "ECS",
                "API": "CreateSnapshot",
                "Parameters": {
                    "DiskId": "{{ DiskId }}",
                    "SnapshotName": "{{ SnapshotName }}"
                }
            },
            "Outputs": {
                "SnapshotId": {
                    "Type": "String",
                    "ValueSelector": "SnapshotId"
                }
            }
        },
        {   
            "Name": "waitSnapshotsReady",
            "Action": "ACS::WaitFor",
            "Properties": {
                "Service": "ECS",
                "API": "DescribeSnapshots",
                "DesiredValues": ["accomplished"],
                "Parameters": {
                    "SnapshotIds": ["{{ createSnapshot.SnapshotId }}"]
                },
                "PropertySelector": "Snapshots.Snapshot[].Status"
            }
        }
    ],
    "Outputs": {
        "SnapshotId": {
            "Type": "String",
            "Value": "{{ createSnapshot.SnapshotId }}"
        }
    }
}