Runs commands on one or more managed nodes.
See also: AWS API Documentation
See ‘aws help’ for descriptions of global parameters.
send-command
[--instance-ids <value>]
[--targets <value>]
--document-name <value>
[--document-version <value>]
[--document-hash <value>]
[--document-hash-type <value>]
[--timeout-seconds <value>]
[--comment <value>]
[--parameters <value>]
[--output-s3-region <value>]
[--output-s3-bucket-name <value>]
[--output-s3-key-prefix <value>]
[--max-concurrency <value>]
[--max-errors <value>]
[--service-role-arn <value>]
[--notification-config <value>]
[--cloud-watch-output-config <value>]
[--cli-input-json | --cli-input-yaml]
[--generate-cli-skeleton <value>]
--instance-ids
(list)
The IDs of the managed nodes where the command should run. Specifying managed node IDs is most useful when you are targeting a limited number of managed nodes, though you can specify up to 50 IDs.
To target a larger number of managed nodes, or if you prefer not to list individual node IDs, we recommend using the
Targets
option instead. UsingTargets
, which accepts tag key-value pairs to identify the managed nodes to send commands to, you can a send command to tens, hundreds, or thousands of nodes at once.For more information about how to use targets, see Using targets and rate controls to send commands to a fleet in the Amazon Web Services Systems Manager User Guide .
(string)
Syntax:
"string" "string" ...
--targets
(list)
An array of search criteria that targets managed nodes using a
Key,Value
combination that you specify. Specifying targets is most useful when you want to send a command to a large number of managed nodes at once. UsingTargets
, which accepts tag key-value pairs to identify managed nodes, you can send a command to tens, hundreds, or thousands of nodes at once.To send a command to a smaller number of managed nodes, you can use the
InstanceIds
option instead.For more information about how to use targets, see Sending commands to a fleet in the Amazon Web Services Systems Manager User Guide .
(structure)
An array of search criteria that targets managed nodes using a key-value pair that you specify.
Note
One or more targets must be specified for maintenance window Run Command-type tasks. Depending on the task, targets are optional for other maintenance window task types (Automation, Lambda, and Step Functions). For more information about running tasks that don’t specify targets, see Registering maintenance window tasks without targets in the Amazon Web Services Systems Manager User Guide .
Supported formats include the following.
Key=InstanceIds,Values=<instance-id-1>,<instance-id-2>,<instance-id-3>
Key=tag:<my-tag-key>,Values=<my-tag-value-1>,<my-tag-value-2>
Key=tag-key,Values=<my-tag-key-1>,<my-tag-key-2>
Run Command and Maintenance window targets only :
Key=resource-groups:Name,Values=<resource-group-name>
Maintenance window targets only :
Key=resource-groups:ResourceTypeFilters,Values=<resource-type-1>,<resource-type-2>
Automation targets only :
Key=ResourceGroup;Values=<resource-group-name>
For example:
Key=InstanceIds,Values=i-02573cafcfEXAMPLE,i-0471e04240EXAMPLE,i-07782c72faEXAMPLE
Key=tag:CostCenter,Values=CostCenter1,CostCenter2,CostCenter3
Key=tag-key,Values=Name,Instance-Type,CostCenter
Run Command and Maintenance window targets only :
Key=resource-groups:Name,Values=ProductionResourceGroup
This example demonstrates how to target all resources in the resource group ProductionResourceGroup in your maintenance window.Maintenance window targets only :
Key=resource-groups:ResourceTypeFilters,Values=AWS::EC2::INSTANCE,AWS::EC2::VPC
This example demonstrates how to target only Amazon Elastic Compute Cloud (Amazon EC2) instances and VPCs in your maintenance window.Automation targets only :
Key=ResourceGroup,Values=MyResourceGroup
State Manager association targets only :
Key=InstanceIds,Values=*
This example demonstrates how to target all managed instances in the Amazon Web Services Region where the association was created.For more information about how to send commands that target managed nodes using
Key,Value
parameters, see Targeting multiple instances in the Amazon Web Services Systems Manager User Guide .Key -> (string)
User-defined criteria for sending commands that target managed nodes that meet the criteria.
Values -> (list)
User-defined criteria that maps to
Key
. For example, if you specifiedtag:ServerRole
, you could specifyvalue:WebServer
to run a command on instances that include EC2 tags ofServerRole,WebServer
.Depending on the type of target, the maximum number of values for a key might be lower than the global maximum of 50.
(string)
Shorthand Syntax:
Key=string,Values=string,string ...
JSON Syntax:
[
{
"Key": "string",
"Values": ["string", ...]
}
...
]
--document-name
(string)
The name of the Amazon Web Services Systems Manager document (SSM document) to run. This can be a public document or a custom document. To run a shared document belonging to another account, specify the document Amazon Resource Name (ARN). For more information about how to use shared documents, see Using shared SSM documents in the Amazon Web Services Systems Manager User Guide .
Note
If you specify a document name or ARN that hasn’t been shared with your account, you receive an
InvalidDocument
error.
--document-version
(string)
The SSM document version to use in the request. You can specify $DEFAULT, $LATEST, or a specific version number. If you run commands by using the Command Line Interface (Amazon Web Services CLI), then you must escape the first two options by using a backslash. If you specify a version number, then you don’t need to use the backslash. For example:
—document-version “$DEFAULT”
–document-version “$LATEST”
—document-version “3”
--document-hash
(string)
The Sha256 or Sha1 hash created by the system when the document was created.
Note
Sha1 hashes have been deprecated.
--document-hash-type
(string)
Sha256 or Sha1.
Note
Sha1 hashes have been deprecated.
Possible values:
Sha256
Sha1
--timeout-seconds
(integer)
If this time is reached and the command hasn’t already started running, it won’t run.
--comment
(string)
User-specified information about the command, such as a brief description of what the command should do.
--parameters
(map)
The required and optional parameters specified in the document being run.
key -> (string)
value -> (list)
(string)
Shorthand Syntax:
KeyName1=string,string,KeyName2=string,string
JSON Syntax:
{"string": ["string", ...]
...}
--output-s3-region
(string)
(Deprecated) You can no longer specify this parameter. The system ignores it. Instead, Systems Manager automatically determines the Amazon Web Services Region of the S3 bucket.
--output-s3-bucket-name
(string)
The name of the S3 bucket where command execution responses should be stored.
--output-s3-key-prefix
(string)
The directory structure within the S3 bucket where the responses should be stored.
--max-concurrency
(string)
(Optional) The maximum number of managed nodes that are allowed to run the command at the same time. You can specify a number such as 10 or a percentage such as 10%. The default value is
50
. For more information about how to useMaxConcurrency
, see Using concurrency controls in the Amazon Web Services Systems Manager User Guide .
--max-errors
(string)
The maximum number of errors allowed without the command failing. When the command fails one more time beyond the value of
MaxErrors
, the systems stops sending the command to additional targets. You can specify a number like 10 or a percentage like 10%. The default value is0
. For more information about how to useMaxErrors
, see Using error controls in the Amazon Web Services Systems Manager User Guide .
--service-role-arn
(string)
The ARN of the Identity and Access Management (IAM) service role to use to publish Amazon Simple Notification Service (Amazon SNS) notifications for Run Command commands.
--notification-config
(structure)
Configurations for sending notifications.
NotificationArn -> (string)
An Amazon Resource Name (ARN) for an Amazon Simple Notification Service (Amazon SNS) topic. Run Command pushes notifications about command status changes to this topic.
NotificationEvents -> (list)
The different events for which you can receive notifications. To learn more about these events, see Monitoring Systems Manager status changes using Amazon SNS notifications in the Amazon Web Services Systems Manager User Guide .
(string)
NotificationType -> (string)
The type of notification.
Command
: Receive notification when the status of a command changes.
Invocation
: For commands sent to multiple managed nodes, receive notification on a per-node basis when the status of a command changes.
Shorthand Syntax:
NotificationArn=string,NotificationEvents=string,string,NotificationType=string
JSON Syntax:
{
"NotificationArn": "string",
"NotificationEvents": ["All"|"InProgress"|"Success"|"TimedOut"|"Cancelled"|"Failed", ...],
"NotificationType": "Command"|"Invocation"
}
--cloud-watch-output-config
(structure)
Enables Amazon Web Services Systems Manager to send Run Command output to Amazon CloudWatch Logs. Run Command is a capability of Amazon Web Services Systems Manager.
CloudWatchLogGroupName -> (string)
The name of the CloudWatch Logs log group where you want to send command output. If you don’t specify a group name, Amazon Web Services Systems Manager automatically creates a log group for you. The log group uses the following naming format:
``aws/ssm/SystemsManagerDocumentName ``
CloudWatchOutputEnabled -> (boolean)
Enables Systems Manager to send command output to CloudWatch Logs.
Shorthand Syntax:
CloudWatchLogGroupName=string,CloudWatchOutputEnabled=boolean
JSON Syntax:
{
"CloudWatchLogGroupName": "string",
"CloudWatchOutputEnabled": true|false
}
--cli-input-json
| --cli-input-yaml
(string)
Reads arguments from the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton
. If other arguments are provided on the command line, those values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally. This may not be specified along with --cli-input-yaml
.
--generate-cli-skeleton
(string)
Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input
, prints a sample input JSON that can be used as an argument for --cli-input-json
. Similarly, if provided yaml-input
it will print a sample input YAML that can be used with --cli-input-yaml
. If provided with the value output
, it validates the command inputs and returns a sample output JSON for that command. The generated JSON skeleton is not stable between versions of the AWS CLI and there are no backwards compatibility guarantees in the JSON skeleton generated.
See ‘aws help’ for descriptions of global parameters.
Note
To use the following examples, you must have the AWS CLI installed and configured. See the Getting started guide in the AWS CLI User Guide for more information.
Unless otherwise stated, all examples have unix-like quotation rules. These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide .
Example 1: To run a command on one or more remote instances
The following send-command
example runs an echo
command on a target instance.
aws ssm send-command \
--document-name "AWS-RunShellScript" \
--parameters 'commands=["echo HelloWorld"]' \
--targets "Key=instanceids,Values=i-1234567890abcdef0" \
--comment "echo HelloWorld"
Output:
{
"Command": {
"CommandId": "92853adf-ba41-4cd6-9a88-142d1EXAMPLE",
"DocumentName": "AWS-RunShellScript",
"DocumentVersion": "",
"Comment": "echo HelloWorld",
"ExpiresAfter": 1550181014.717,
"Parameters": {
"commands": [
"echo HelloWorld"
]
},
"InstanceIds": [
"i-0f00f008a2dcbefe2"
],
"Targets": [],
"RequestedDateTime": 1550173814.717,
"Status": "Pending",
"StatusDetails": "Pending",
"OutputS3BucketName": "",
"OutputS3KeyPrefix": "",
"MaxConcurrency": "50",
"MaxErrors": "0",
"TargetCount": 1,
"CompletedCount": 0,
"ErrorCount": 0,
"DeliveryTimedOutCount": 0,
"ServiceRole": "",
"NotificationConfig": {
"NotificationArn": "",
"NotificationEvents": [],
"NotificationType": ""
},
"CloudWatchOutputConfig": {
"CloudWatchLogGroupName": "",
"CloudWatchOutputEnabled": false
}
}
}
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Examle 2: To get IP information about an instance
The following send-command
example retrieves the IP information about an instance.
aws ssm send-command \
--instance-ids "i-1234567890abcdef0" \
--document-name "AWS-RunShellScript" \
--comment "IP config" \
--parameters "commands=ifconfig"
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 3: To run a command on instances with specific tags
The following send-command
example runs a command on instances that have the tag key “ENV” and the value “Dev”.
aws ssm send-command \
--targets "Key=tag:ENV,Values=Dev" \
--document-name "AWS-RunShellScript" \
--parameters "commands=ifconfig"
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 4: To run a command that sends SNS notifications
The following send-command
example runs a command that sends SNS notifications for all notification events and the Command
notification type.
aws ssm send-command \
--instance-ids "i-1234567890abcdef0" \
--document-name "AWS-RunShellScript" \
--comment "IP config" \
--parameters "commands=ifconfig" \
--service-role-arn "arn:aws:iam::123456789012:role/SNS_Role" \
--notification-config "NotificationArn=arn:aws:sns:us-east-1:123456789012:SNSTopicName,NotificationEvents=All,NotificationType=Command"
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 5: To run a command that outputs to S3 and CloudWatch
The following send-command
example runs a command that outputs command details to an S3 bucket and to a CloudWatch Logs log group.
aws ssm send-command \
--instance-ids "i-1234567890abcdef0" \
--document-name "AWS-RunShellScript" \
--comment "IP config" \
--parameters "commands=ifconfig" \
--output-s3-bucket-name "s3-bucket-name" \
--output-s3-key-prefix "runcommand" \
--cloud-watch-output-config "CloudWatchOutputEnabled=true,CloudWatchLogGroupName=CWLGroupName"
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 6: To run commands on multiple instances with different tags
The following send-command
example runs a command on instances with two different tag keys and values.
aws ssm send-command \
--document-name "AWS-RunPowerShellScript" \
--parameters commands=["echo helloWorld"] \
--targets Key=tag:Env,Values=Dev Key=tag:Role,Values=WebServers
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 7: To target multiple instances with the same tag key
The following send-command
example runs a command on instances that have the same tag key but with different values.
aws ssm send-command \
--document-name "AWS-RunPowerShellScript" \
--parameters commands=["echo helloWorld"] \
--targets Key=tag:Env,Values=Dev,Test
See example 1 for sample output.
For more information, see Running Commands Using Systems Manager Run Command in the AWS Systems Manager User Guide.
Example 8: To run a command that uses a shared document
The following send-command
example runs a shared document on a target instance.
aws ssm send-command \
--document-name "arn:aws:ssm:us-east-1:123456789012:document/ExampleDocument" \
--targets "Key=instanceids,Values=i-1234567890abcdef0"
See example 1 for sample output.
For more information, see Using shared SSM documents in the AWS Systems Manager User Guide.
Command -> (structure)
The request as it was received by Systems Manager. Also provides the command ID which can be used future references to this request.
CommandId -> (string)
A unique identifier for this command.
DocumentName -> (string)
The name of the document requested for execution.
DocumentVersion -> (string)
The Systems Manager document (SSM document) version.
Comment -> (string)
User-specified information about the command, such as a brief description of what the command should do.
ExpiresAfter -> (timestamp)
If a command expires, it changes status to
DeliveryTimedOut
for all invocations that have the statusInProgress
,Pending
, orDelayed
.ExpiresAfter
is calculated based on the total timeout for the overall command. For more information, see Understanding command timeout values in the Amazon Web Services Systems Manager User Guide .Parameters -> (map)
The parameter values to be inserted in the document when running the command.
key -> (string)
value -> (list)
(string)
InstanceIds -> (list)
The managed node IDs against which this command was requested.
(string)
Targets -> (list)
An array of search criteria that targets managed nodes using a Key,Value combination that you specify. Targets is required if you don’t provide one or more managed node IDs in the call.
(structure)
An array of search criteria that targets managed nodes using a key-value pair that you specify.
Note
One or more targets must be specified for maintenance window Run Command-type tasks. Depending on the task, targets are optional for other maintenance window task types (Automation, Lambda, and Step Functions). For more information about running tasks that don’t specify targets, see Registering maintenance window tasks without targets in the Amazon Web Services Systems Manager User Guide .
Supported formats include the following.
Key=InstanceIds,Values=<instance-id-1>,<instance-id-2>,<instance-id-3>
Key=tag:<my-tag-key>,Values=<my-tag-value-1>,<my-tag-value-2>
Key=tag-key,Values=<my-tag-key-1>,<my-tag-key-2>
Run Command and Maintenance window targets only :
Key=resource-groups:Name,Values=<resource-group-name>
Maintenance window targets only :
Key=resource-groups:ResourceTypeFilters,Values=<resource-type-1>,<resource-type-2>
Automation targets only :
Key=ResourceGroup;Values=<resource-group-name>
For example:
Key=InstanceIds,Values=i-02573cafcfEXAMPLE,i-0471e04240EXAMPLE,i-07782c72faEXAMPLE
Key=tag:CostCenter,Values=CostCenter1,CostCenter2,CostCenter3
Key=tag-key,Values=Name,Instance-Type,CostCenter
Run Command and Maintenance window targets only :
Key=resource-groups:Name,Values=ProductionResourceGroup
This example demonstrates how to target all resources in the resource group ProductionResourceGroup in your maintenance window.Maintenance window targets only :
Key=resource-groups:ResourceTypeFilters,Values=AWS::EC2::INSTANCE,AWS::EC2::VPC
This example demonstrates how to target only Amazon Elastic Compute Cloud (Amazon EC2) instances and VPCs in your maintenance window.Automation targets only :
Key=ResourceGroup,Values=MyResourceGroup
State Manager association targets only :
Key=InstanceIds,Values=*
This example demonstrates how to target all managed instances in the Amazon Web Services Region where the association was created.For more information about how to send commands that target managed nodes using
Key,Value
parameters, see Targeting multiple instances in the Amazon Web Services Systems Manager User Guide .Key -> (string)
User-defined criteria for sending commands that target managed nodes that meet the criteria.
Values -> (list)
User-defined criteria that maps to
Key
. For example, if you specifiedtag:ServerRole
, you could specifyvalue:WebServer
to run a command on instances that include EC2 tags ofServerRole,WebServer
.Depending on the type of target, the maximum number of values for a key might be lower than the global maximum of 50.
(string)
RequestedDateTime -> (timestamp)
The date and time the command was requested.
Status -> (string)
The status of the command.
StatusDetails -> (string)
A detailed status of the command execution.
StatusDetails
includes more information thanStatus
because it includes states resulting from error and concurrency control parameters.StatusDetails
can show different results than Status. For more information about these statuses, see Understanding command statuses in the Amazon Web Services Systems Manager User Guide . StatusDetails can be one of the following values:
Pending: The command hasn’t been sent to any managed nodes.
In Progress: The command has been sent to at least one managed node but hasn’t reached a final state on all managed nodes.
Success: The command successfully ran on all invocations. This is a terminal state.
Delivery Timed Out: The value of MaxErrors or more command invocations shows a status of Delivery Timed Out. This is a terminal state.
Execution Timed Out: The value of MaxErrors or more command invocations shows a status of Execution Timed Out. This is a terminal state.
Failed: The value of MaxErrors or more command invocations shows a status of Failed. This is a terminal state.
Incomplete: The command was attempted on all managed nodes and one or more invocations doesn’t have a value of Success but not enough invocations failed for the status to be Failed. This is a terminal state.
Cancelled: The command was terminated before it was completed. This is a terminal state.
Rate Exceeded: The number of managed nodes targeted by the command exceeded the account limit for pending invocations. The system has canceled the command before running it on any managed node. This is a terminal state.
Delayed: The system attempted to send the command to the managed node but wasn’t successful. The system retries again.
OutputS3Region -> (string)
(Deprecated) You can no longer specify this parameter. The system ignores it. Instead, Systems Manager automatically determines the Amazon Web Services Region of the S3 bucket.
OutputS3BucketName -> (string)
The S3 bucket where the responses to the command executions should be stored. This was requested when issuing the command.
OutputS3KeyPrefix -> (string)
The S3 directory path inside the bucket where the responses to the command executions should be stored. This was requested when issuing the command.
MaxConcurrency -> (string)
The maximum number of managed nodes that are allowed to run the command at the same time. You can specify a number of managed nodes, such as 10, or a percentage of nodes, such as 10%. The default value is 50. For more information about how to use
MaxConcurrency
, see Running commands using Systems Manager Run Command in the Amazon Web Services Systems Manager User Guide .MaxErrors -> (string)
The maximum number of errors allowed before the system stops sending the command to additional targets. You can specify a number of errors, such as 10, or a percentage or errors, such as 10%. The default value is
0
. For more information about how to useMaxErrors
, see Running commands using Systems Manager Run Command in the Amazon Web Services Systems Manager User Guide .TargetCount -> (integer)
The number of targets for the command.
CompletedCount -> (integer)
The number of targets for which the command invocation reached a terminal state. Terminal states include the following: Success, Failed, Execution Timed Out, Delivery Timed Out, Cancelled, Terminated, or Undeliverable.
ErrorCount -> (integer)
The number of targets for which the status is Failed or Execution Timed Out.
DeliveryTimedOutCount -> (integer)
The number of targets for which the status is Delivery Timed Out.
ServiceRole -> (string)
The Identity and Access Management (IAM) service role that Run Command, a capability of Amazon Web Services Systems Manager, uses to act on your behalf when sending notifications about command status changes.
NotificationConfig -> (structure)
Configurations for sending notifications about command status changes.
NotificationArn -> (string)
An Amazon Resource Name (ARN) for an Amazon Simple Notification Service (Amazon SNS) topic. Run Command pushes notifications about command status changes to this topic.
NotificationEvents -> (list)
The different events for which you can receive notifications. To learn more about these events, see Monitoring Systems Manager status changes using Amazon SNS notifications in the Amazon Web Services Systems Manager User Guide .
(string)
NotificationType -> (string)
The type of notification.
Command
: Receive notification when the status of a command changes.
Invocation
: For commands sent to multiple managed nodes, receive notification on a per-node basis when the status of a command changes.CloudWatchOutputConfig -> (structure)
Amazon CloudWatch Logs information where you want Amazon Web Services Systems Manager to send the command output.
CloudWatchLogGroupName -> (string)
The name of the CloudWatch Logs log group where you want to send command output. If you don’t specify a group name, Amazon Web Services Systems Manager automatically creates a log group for you. The log group uses the following naming format:
``aws/ssm/SystemsManagerDocumentName ``
CloudWatchOutputEnabled -> (boolean)
Enables Systems Manager to send command output to CloudWatch Logs.
TimeoutSeconds -> (integer)
The
TimeoutSeconds
value specified for a command.