GetAutomationExecution 搭配 CLI 使用 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

GetAutomationExecution 搭配 CLI 使用

下列程式碼範例示範如何使用 GetAutomationExecution

CLI
AWS CLI

若要顯示自動化執行的詳細資訊

下列get-automation-execution範例顯示自動化執行的詳細資訊。

aws ssm get-automation-execution \ --automation-execution-id 73c8eef8-f4ee-4a05-820c-e354fEXAMPLE

輸出:

{ "AutomationExecution": { "AutomationExecutionId": "73c8eef8-f4ee-4a05-820c-e354fEXAMPLE", "DocumentName": "AWS-StartEC2Instance", "DocumentVersion": "1", "ExecutionStartTime": 1583737233.748, "ExecutionEndTime": 1583737234.719, "AutomationExecutionStatus": "Success", "StepExecutions": [ { "StepName": "startInstances", "Action": "aws:changeInstanceState", "ExecutionStartTime": 1583737234.134, "ExecutionEndTime": 1583737234.672, "StepStatus": "Success", "Inputs": { "DesiredState": "\"running\"", "InstanceIds": "[\"i-0cb99161f6EXAMPLE\"]" }, "Outputs": { "InstanceStates": [ "running" ] }, "StepExecutionId": "95e70479-cf20-4d80-8018-7e4e2EXAMPLE", "OverriddenParameters": {} } ], "StepExecutionsTruncated": false, "Parameters": { "AutomationAssumeRole": [ "" ], "InstanceId": [ "i-0cb99161f6EXAMPLE" ] }, "Outputs": {}, "Mode": "Auto", "ExecutedBy": "arn:aws:sts::29884EXAMPLE:assumed-role/mw_service_role/OrchestrationService", "Targets": [], "ResolvedTargets": { "ParameterValues": [], "Truncated": false } } }

如需詳細資訊,請參閱 AWS Systems Manager 使用者指南中的逐步解說:修補 Linux AMI (AWS CLI)

PowerShell
for PowerShell 工具

範例 1:此範例顯示 Automation Execution 的詳細資訊。

Get-SSMAutomationExecution -AutomationExecutionId "4105a4fc-f944-11e6-9d32-8fb2db27a909"

輸出:

AutomationExecutionId : 4105a4fc-f944-11e6-9d32-8fb2db27a909 AutomationExecutionStatus : Failed DocumentName : AWS-UpdateLinuxAmi DocumentVersion : 1 ExecutionEndTime : 2/22/2017 9:17:08 PM ExecutionStartTime : 2/22/2017 9:17:02 PM FailureMessage : Step launchInstance failed maximum allowed times. You are not authorized to perform this operation. Encoded authorization failure message: B_V2QyyN7NhSZQYpmVzpEc4oSnj2GLTNYnXUHsTbqJkNMoDgubmbtthLmZyaiUYekORIrA42-fv1x-04q5Fjff6glh Yb6TI5b0GQeeNrpwNvpDzmO-PSR1swlAbg9fdM9BcNjyrznspUkWpuKu9EC1Ou6v3OXU1KC9nZ7mPlWMFZNkSioQqpwWEvMw-GZktsQzm67qOhUhBNOLWYhbS pkfiqzY-5nw3S0obx30fhd3EJa5O_-GjV_a0nFXQJa70ik40bFOrEh3MtCSbrQT6--DvFy_FQ8TKvkIXadyVskeJI84XOF5WmA60f1pi5GI08i-nRfZS6oDeU gELBjjoFKD8s3L2aI0B6umWVxnQOjqhQRxwJ53b54sZJ2PW3v_mtg9-q0CK0ezS3xfh_y0ilaUGOAZG-xjQFuvU_JZedWpla3xi-MZsmblAifBI (Service: AmazonEC2; Status Code: 403; Error Code: UnauthorizedOperation; Request ID: 6a002f94-ba37-43fd-99e6-39517715fce5) Outputs : {[createImage.ImageId, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]} Parameters : {[AutomationAssumeRole, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]], [InstanceIamRole, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]], [SourceAmiId, Amazon.Runtime.Internal.Util.AlwaysSendList`1[System.String]]} StepExecutions : {launchInstance, updateOSSoftware, stopInstance, createImage...}

範例 2:此範例列出指定自動化執行 ID 的步驟詳細資訊

Get-SSMAutomationExecution -AutomationExecutionId e1d2bad3-4567-8901-ae23-456c7c8901be | Select-Object -ExpandProperty StepExecutions | Select-Object StepName, Action, StepStatus, ValidNextSteps

輸出:

StepName Action StepStatus ValidNextSteps -------- ------ ---------- -------------- LaunchInstance aws:runInstances Success {OSCompatibilityCheck} OSCompatibilityCheck aws:runCommand Success {RunPreUpdateScript} RunPreUpdateScript aws:runCommand Success {UpdateEC2Config} UpdateEC2Config aws:runCommand Cancelled {} UpdateSSMAgent aws:runCommand Pending {} UpdateAWSPVDriver aws:runCommand Pending {} UpdateAWSEnaNetworkDriver aws:runCommand Pending {} UpdateAWSNVMe aws:runCommand Pending {} InstallWindowsUpdates aws:runCommand Pending {} RunPostUpdateScript aws:runCommand Pending {} RunSysprepGeneralize aws:runCommand Pending {} StopInstance aws:changeInstanceState Pending {} CreateImage aws:createImage Pending {} TerminateInstance aws:changeInstanceState Pending {}