将 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 用户指南》中的查看关联历史记录。
-
有关 API 详细信息,请参阅《AWS CLI Command Reference》中的 DescribeAssociationExecutionTargets
。
-
- PowerShell
-
- 适用于 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 Reference》中的 DescribeAssociationExecutionTargets。
-
有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将 Systems Manager 与 AWS SDK 配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。
DescribeAssociation
DescribeAssociationExecutions