Menu
Amazon Elastic Compute Cloud
User Guide for Linux Instances

Running Commands on Amazon EC2 Instances Using the Console

The following walkthrough shows you how to use Run Command to execute commands on your Linux instance from the Amazon EC2 console. You specify a command or a script using the AWS-RunShellScript SSM JSON document. For example, you can specify commands like curl or service --status-all.

For an example that uses the AWS CLI, see Amazon EC2 Run Command Walkthrough Using the AWS CLI.

For examples that use a Windows instance, see Amazon EC2 Run Command Walkthrough Using the Console in the Amazon EC2 User Guide for Windows Instances.

To execute a command using Run Command from the console

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. In the navigation pane, choose Run Command.

  3. Choose Run a command.

  4. For Command document, choose AWS-RunShellScript.

  5. For Target instances, choose the instances where you want the command to run. If you do not see an instance in this list, it might not be configured properly for Run Command. For more information, see Systems Manager Prerequisites.

  6. For Commands, type a valid shell script or command.

  7. (Optional) For Working Directory, type the path to the folder on your EC2 instances where you want to run the command.

  8. (Optional) For Execution Timeout, type the number of seconds the EC2Config service or SSM agent will attempt to run the command before it times out and fails.

  9. For Comment, we recommend providing information that will help you identify this command in your list of commands.

  10. For Timeout (seconds), type the number of seconds that Run Command should attempt to reach an instance before it is considered unreachable and the command execution fails. The minimum is 30 seconds, the maximum is 30 days, and the default is 10 minutes.

  11. For S3 bucket, type the name of the S3 bucket for the command output. For S3 key prefix, type the name of a subfolder in the S3 bucket. A subfolder can help you organize Run Command output if you execute multiple commands against multiple instances.

  12. Choose Run to execute the command simultaneously on all the selected instances. Run Command displays a status screen. Choose View result.

  13. (Optional) If the command is pending or executing, you can attempt to cancel it. Choose the invocation, and then choose Actions, Cancel. Note that we can't guarantee that the command will be canceled.

  14. The command list shows one invocation of the command per instance. Each invocation has it's own command ID and status. To view the output, choose an invocation, choose the Output tab, and then choose View Output.

    The system displays the output in your browser. Note that if the output is longer than 2500 characters, only the first 2500 characters are shown and the rest is truncated.

  15. To view the full command output in Amazon S3, open the Amazon S3 console and choose your Amazon S3 bucket. Choose the folder with the command ID and instance ID for which you want to view command output. Choose the awsrunPowerShellScript sub-folder. The stdout.text file contains the full command output.