Description
The ACS::CheckFor action can be used to check whether cloud resources are in the expected state. If the resources are in the specified state, the task is successful. Otherwise, the task fails. This action is usually used to perform prechecks. For example, if you want to stop an Elastic Compute Service (ECS) instance, you can first check whether the instance is in the Running state. You can stop the instance only if it is in the Running state.
Syntax
Except that the Action
attribute is set to ACS::CheckFor
, all other attributes of the ACS::CheckFor action are the same as those of the ACS::WaitFor
action. For more information, see the syntax description of the ACS::WaitFor action.
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"
}
}
}
]
}
Examples
The following sample code provides an example on how to create a snapshot for the specified disk. In this example, the ACS::CheckFor action is used to check whether the specified ECS instance is in the Running or Stopped state.
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 }}"
}
}
}