I want to troubleshoot errors that occur when I use Run Command, a capability of AWS Systems Manager, to run commands on my managed Amazon Elastic Compute Cloud (Amazon EC2) instance.
Resolution
Prerequisites: You must configure an AWS Identity and Access Management (IAM) user policy before you use Run Command to manage EC2 instances. The user policy is required for users that run commands. To verify that you have configured the necessary policies, complete the following actions, or configure:
- Check that you attached an IAM instance profile role for Systems Manager to your instances. For more information, see Configure instance permissions for Systems Manager.
- Check that the role or user's IAM policy has permissions to use the necessary API operations. For more information on the API operations that your instance requires, see Agent-related API operations (ssmmessages and ec2messages endpoints).
Or, use the Default Host Management Configuration setting. Systems Manager automatically manages instances without an IAM instance profile when you activate Default Host Management Configuration. Default Host Management Configuration is available in AWS Systems Manager Agent (SSM Agent) version 3.2.582.0 or later. Be sure to complete the necessary prerequisites before you activate Default Host Management Configuration
Note: If you use you activate Default Host Management Configuration, then all the associated instances must use Instance Metadata Service Version 2 (IMDSv2).
Troubleshoot Run Command failures
In the Systems Manager console, under Fleet Manager, the instance must appear as a managed instance, and the SSM Agent ping status must be Online. If Run Command fails, then complete the following actions:
- Verify that your instance uses the latest version of SSM Agent.
- To troubleshoot an instance that doesn't appear as a managed instance, see Why isn't Systems Manager showing my Amazon EC2 instance as a managed instance?
- Verify that SSM Agent functions correctly. For information about how to resolve issues with SSM Agent, see Troubleshooting SSM Agent.
- When Maintenance Windows, a capability of AWS Systems Manager, or State Manager runs the command, confirm that the command successfully runs. To check that your commands successfully run, use AWS CloudTrail to review the responses to the SendCommand API operation.
Review Run Command status details
Complete the following steps:
- Review the Run Command status details.
- Open the Systems Manager console.
- In the navigation pane, select Run Command.
- (Optional) to check a Run command that you used in the past, choose the Command history tab.
- Choose the Command ID that corresponds with your command to open the Command status page.
- From the Targets and outputs section, choose the Instance ID that corresponds to your instance, and then review the output.
If the output is truncated, then use SSH to and then navigate to the following directories to see the full error details:
Important: Some plugins run only on either Windows Server instances or Linux instances. For a list of plugins that you can specify in a Command document, and each plugin's platform dependencies, see Command document plugin reference.
For Linux and macOS:
- /var/lib/amazon/ssm/example-instance-ID/document/orchestration/example-command-id/example-plugin-name/example-step-name/stdout
- /var/lib/amazon/ssm/example-instance-ID/document/orchestration/example-command-id/example-plugin-name/example-step-name/stderr
For Windows:
- %ProgramData%\Amazon\SSM\InstanceData\example-instance-ID\document\orchestration\example-command-id\example-plugin-name\example-step-name\stdout
- %ProgramData%\Amazon\SSM\InstanceData\example-instance-ID\document\orchestration\example-command-id\example-plugin-name\example-step-name\stderr\
Note: Replace example-instance-ID with your instance's ID number. Replace example-command-ID, with your command ID. Replace example-plugin-name with the name of the plugin that you specify in your Command document. Replace example-step-name with the name value that corresponds with the plugin that you specify in the mainSteps section of your Command document.
Review the exit status codes in your exit details then use your exit status codes troubleshoot Run Command.
Review SSM Agent logs
Review your SSM Agent logs for more details about the failure, then use your logs to troubleshoot errors that you find. If your SSM Agent logs don't provide the necessary information to resolve your error, then allow SSM Agent debug logging to reproduce the issue.
Important: The AWS Systems Manager CloudWatch Dashboard will no longer be available after April 30, 2026. Use the CloudWatch console to view, create, and manage your CloudWatch dashboards.
Related information
AWS Systems Manager documents
Setting up AWS Systems Manager