本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭配使用 DescribeAssociationExecutionTargets
與 CLI
下列程式碼範例示範如何使用 DescribeAssociationExecutionTargets
。
- CLI
-
- AWS CLI
-
取得關聯執行的詳細資訊
下列
describe-association-execution-targets
範例說明指定的關聯執行。aws ssm describe-association-execution-targets \ --association-id
"8dfe3659-4309-493a-8755-0123456789ab"
\ --execution-id"7abb6378-a4a5-4f10-8312-0123456789ab"
輸出:
{ "AssociationExecutionTargets": [ { "AssociationId": "8dfe3659-4309-493a-8755-0123456789ab", "AssociationVersion": "1", "ExecutionId": "7abb6378-a4a5-4f10-8312-0123456789ab", "ResourceId": "i-1234567890abcdef0", "ResourceType": "ManagedInstance", "Status": "Success", "DetailedStatus": "Success", "LastExecutionDate": 1550505538.497, "OutputSource": { "OutputSourceId": "97fff367-fc5a-4299-aed8-0123456789ab", "OutputSourceType": "RunCommand" } } ] }
如需詳細資訊,請參閱《AWS Systems Manager 使用者指南》中的 Viewing association histories。
-
如需 API 詳細資訊,請參閱《AWS CLI 命令參考》中的 DescribeAssociationExecutionTargets
。
-
- PowerShell
-
- Tools for PowerShell
-
範例 1:此範例顯示資源 ID 及其執行狀態,它們是關聯執行目標的一部分
Get-SSMAssociationExecutionTarget -AssociationId 123a45a0-c678-9012-3456-78901234db5e -ExecutionId 123a45a0-c678-9012-3456-78901234db5e | Select-Object ResourceId, Status
輸出:
ResourceId Status ---------- ------ i-0b1b2a3456f7a890b Success i-01c12a45d6fc7a89f Success i-0a1caf234f56d7dc8 Success i-012a3fd45af6dbcfe Failed i-0ddc1df23c4a5fb67 Success
範例 2:此命令會檢查自昨天以來特定自動化的特定執行,其中關聯有命令文件。它會進一步檢查關聯執行是否失敗,如果是,則會顯示該執行的命令調用詳細資訊以及執行個體 ID
$AssociationExecution= Get-SSMAssociationExecutionTarget -AssociationId 1c234567-890f-1aca-a234-5a678d901cb0 -ExecutionId 12345ca12-3456-2345-2b45-23456789012 | Where-Object {$_.LastExecutionDate -gt (Get-Date -Hour 00 -Minute 00).AddDays(-1)} foreach ($execution in $AssociationExecution) { if($execution.Status -ne 'Success'){ Write-Output "There was an issue executing the association $($execution.AssociationId) on $($execution.ResourceId)" Get-SSMCommandInvocation -CommandId $execution.OutputSource.OutputSourceId -Detail:$true | Select-Object -ExpandProperty CommandPlugins } }
輸出:
There was an issue executing the association 1c234567-890f-1aca-a234-5a678d901cb0 on i-0a1caf234f56d7dc8 Name : aws:runPowerShellScript Output : ----------ERROR------- failed to run commands: exit status 1 OutputS3BucketName : OutputS3KeyPrefix : OutputS3Region : eu-west-1 ResponseCode : 1 ResponseFinishDateTime : 5/29/2019 11:04:49 AM ResponseStartDateTime : 5/29/2019 11:04:49 AM StandardErrorUrl : StandardOutputUrl : Status : Failed StatusDetails : Failed
-
如需 API 詳細資訊,請參閱《AWS Tools for PowerShell Cmdlet 參考》中的 DescribeAssociationExecutionTargets。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 將此服務與 AWS SDK 搭配使用。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
DescribeAssociation
DescribeAssociationExecutions