Running Shell Scripts with SSM Run Command
You can use the AWS-RunShellScript command document to run shell scripts on your instances.
Tip
The Commands page in the EC2 console includes a section called AWS Command Line Interface command. This section displays a usable CLI script that is generated based on the parameters you enter.
To run shell scripts using Run Command
Open the Amazon EC2 console and choose Commands in the navigation pane.
Choose Run a Command.
In the Command document list, choose AWS-RunShellScript.
Choose Select target instances to select the instances where you want the command to run. If you do not see a complete list of instances, the missing instances might not be configured properly for Run Command. For more information, see SSM Run Command Prerequisites.
Enter a script or the path to a script in the Commands field.
(Optional) In the Working Directory field, enter the path to the folder on your EC2 instances where you want to run the command.
(Optional) In the Execution Timeout field, enter the number of seconds the Amazon SSM agent will attempt to run the command before it times out and fails.
(Optional) In the Comment field, enter information you want to provide about this command. Comments are stored in the log file and appear in the Command Invocation List in the EC2 console.
Tip
We recommend that you enter specific comments about each command you run. The list of commands that you send can grow quickly, and the Comment field can help you identify commands that you want to monitor.
In the Timeout (seconds) field, enter the number of seconds Run Command should attempt to reach instances before an instance is considered unreachable and the command execution fails. The minimum is 30 seconds. The maximum is 30 days. The default value is 10 minutes.
In the Amazon S3 bucket field enter the name of an Amazon S3 bucket where you want to store the output of the command.
Important
The Run Command Output page in the Amazon EC2 console truncates output after 2500 characters. Configure an Amazon S3 bucket before executing commands with Run Command. If your command output was longer than 2500 characters, you can view the full output in your Amazon S3 bucket. For more information, see Create a Bucket.
In the S3 key prefix, field enter the name of a subfolder in the Amazon S3 bucket. This subfolder can help you organize Run Command output.
For information about how to view the results of your command, see Viewing Command Output in the Amazon EC2 Console.
For information about how to run commands using the AWS CLI, see the SSM CLI Reference.

