All Products
Search
Document Center

ACS__CheckFor

Last Updated: Sep 05, 2019

Features

The ACS::CheckFor action is used to check whether the cloud product instances are in the expected status. If the instances are in the specified status, the task is successful. If the instances are not in the specified status, the task fails. This action is usually used to perform pre-checks. For example, if you want to stop an ECS instance, you can check whether the instance is in the Running status first. If it is not in the Running status, you cannot perform the operation.

Syntax

Except that the Type 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 for the ACS::WaitFor action.

  • YAML format
  1. Tasks:
  2. - Name: checkForTaskExample
  3. Type: ACS::CheckFor
  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::CheckFor 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. DesiredValues: # Either DesiredValues or NotDesiredValues is required. This attribute specifies the expected values. If the value selected by PropertySelector matches one of the following values, the operation is successful. If the value selected by PropertySelector does not match any of the following values, the operation times out and fails.
  13. - value1
  14. - value2
  15. NotDesiredValues: # Either DesiredValues or NotDesiredValues is required. This attribute specifies the values that are not expected. If the value selected by PropertySelector does not match any of the following values, the operation is successful. If the value selected by PropertySelector matches one of the following values, the operation times out and fails.
  16. - value3
  17. - value4
  18. Outputs: # The output parameters of the task where the ACS::CheckFor action resides. When the task is successfully executed, the output parameter values that meet the NotDesiredValues or DesiredValues condition are returned.
  19. OutputParameter1:
  20. 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/.
  21. 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": "checkForTaskExample",
  5. "Type": "ACS::CheckFor",
  6. "Properties": {
  7. "Service": "ECS",
  8. "API": "DescribeInstances",
  9. "Parameters": {
  10. "InstanceId": "i-12345678abcedfg"
  11. },
  12. "PropertySelector": "jq selector",
  13. "DesiredValues": [
  14. "value1",
  15. "value2"
  16. ],
  17. "NotDesiredValues": [
  18. "value3",
  19. "value4"
  20. ]
  21. },
  22. "Outputs": {
  23. "OutputParameter1": {
  24. "ValueSelector": "jq selector",
  25. "Type": "String/Boolean/List(Array)/Number/Object"
  26. }
  27. }
  28. }
  29. ]
  30. }

Example

The following template is used to create a snapshot for the specified disk: Use the ACS::CheckFor action to check whether the specified instance is in the Running or Stopped status.

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Parameters:
  3. DiskId:
  4. Description: the disk id of the snap shot to copy
  5. Type: String
  6. InstanceId:
  7. Description: the instances id of the snap shot to copy
  8. Type: String
  9. SnapshotName:
  10. Description: snap shot name of the new snap
  11. Type: String
  12. Tasks:
  13. - Name: checkInstanceReady
  14. Action: ACS::CheckFor
  15. Properties:
  16. Service: ECS
  17. API: DescribeInstances
  18. DesiredValues:
  19. - Running
  20. - Stopped
  21. Parameters:
  22. InstanceIds:
  23. - '{{ InstanceId }} '
  24. PropertySelector: Instances.Instance[].Status
  25. - Name: createSnapshot
  26. Action: ACS::ExecuteAPI
  27. Properties:
  28. Service: ECS
  29. API: CreateSnapshot
  30. Parameters:
  31. DiskId: '{{ DiskId }}'
  32. SnapshotName: '{{ SnapshotName }}'
  33. Outputs:
  34. SnapshotId:
  35. Type: String
  36. ValueSelector: SnapshotId
  37. - Name: waitSnapshotsReady
  38. Action: ACS::WaitFor
  39. Properties:
  40. Service: ECS
  41. API: DescribeSnapshots
  42. DesiredValues:
  43. - accomplished
  44. Parameters:
  45. SnapshotIds:
  46. - '{{ createSnapshot.SnapshotId }}'
  47. PropertySelector: Snapshots.Snapshot[].Status
  48. Outputs:
  49. SnapshotId:
  50. Type: String
  51. Value: '{{ createSnapshot.SnapshotId }}'
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Parameters": {
  4. "DiskId": {
  5. "Description": "the disk id of the snap shot to copy ",
  6. "Type": "String"
  7. },
  8. "InstanceId": {
  9. "Description": "the instances id of the snap shot to copy ",
  10. "Type": "String"
  11. },
  12. "SnapshotName": {
  13. "Description": "snap shot name of the new snap",
  14. "Type": "String"
  15. }
  16. },
  17. "Tasks": [
  18. {
  19. "Name": "checkInstanceReady",
  20. "Action": "ACS::CheckFor",
  21. "Properties": {
  22. "Service": "ECS",
  23. "API": "DescribeInstances",
  24. "DesiredValues": ["Running", "Stopped"],
  25. "Parameters": {
  26. "InstanceIds": ["{{ InstanceId }} "]
  27. },
  28. "PropertySelector": "Instances.Instance[].Status"
  29. }
  30. },
  31. {
  32. "Name": "createSnapshot",
  33. "Action": "ACS::ExecuteAPI",
  34. "Properties": {
  35. "Service": "ECS",
  36. "API": "CreateSnapshot",
  37. "Parameters": {
  38. "DiskId": "{{ DiskId }}",
  39. "SnapshotName": "{{ SnapshotName }}"
  40. }
  41. },
  42. "Outputs": {
  43. "SnapshotId": {
  44. "Type": "String",
  45. "ValueSelector": "SnapshotId"
  46. }
  47. }
  48. },
  49. {
  50. "Name": "waitSnapshotsReady",
  51. "Action": "ACS::WaitFor",
  52. "Properties": {
  53. "Service": "ECS",
  54. "API": "DescribeSnapshots",
  55. "DesiredValues": ["accomplished"],
  56. "Parameters": {
  57. "SnapshotIds": ["{{ createSnapshot.SnapshotId }}"]
  58. },
  59. "PropertySelector": "Snapshots.Snapshot[].Status"
  60. }
  61. }
  62. ],
  63. "Outputs": {
  64. "SnapshotId": {
  65. "Type": "String",
  66. "Value": "{{ createSnapshot.SnapshotId }}"
  67. }
  68. }
  69. }