Descrição
A ação ACS::CheckFor verifica se os recursos de nuvem estão no estado esperado. Se os recursos estiverem no estado especificado, a tarefa será concluída com sucesso; caso contrário, falhará. Essa ação é geralmente usada para pré-verificações. Por exemplo, antes de parar uma instância do Elastic Compute Service (ECS), use esta ação para verificar se a instância está no estado Running.
Sintaxe
Todos os atributos da ação ACS::CheckFor são idênticos aos da ação ACS::WaitFor, exceto o atributo Action, que deve ser definido como ACS::CheckFor. Para mais informações, consulte a descrição de sintaxe da ação 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"
}
}
}
]
}
Exemplos
O exemplo a seguir mostra como criar um snapshot para um disco específico. A ação ACS::CheckFor verifica primeiro se a instância ECS especificada está no estado 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 }}"
}
}
}