Skip to content

send_command

send_command(
    document_name: DocumentARN,
    *,
    config_overrides: Optional[SSMClientConfig] = None,
    instance_ids: Optional[InstanceIdList] = None,
    targets: Optional[Targets] = None,
    document_version: Optional[DocumentVersion] = None,
    document_hash: Optional[DocumentHash] = None,
    document_hash_type: Optional[DocumentHashType] = None,
    timeout_seconds: Optional[TimeoutSeconds] = None,
    comment: Optional[Comment] = None,
    parameters: Optional[Parameters] = None,
    output_s3_region: Optional[S3Region] = None,
    output_s3_bucket_name: Optional[S3BucketName] = None,
    output_s3_key_prefix: Optional[S3KeyPrefix] = None,
    max_concurrency: Optional[MaxConcurrency] = None,
    max_errors: Optional[MaxErrors] = None,
    service_role_arn: Optional[ServiceRole] = None,
    notification_config: Optional[NotificationConfig] = None,
    cloud_watch_output_config: Optional[CloudWatchOutputConfig] = None,
    alarm_configuration: Optional[AlarmConfiguration] = None,
) -> SendCommandResult

Runs commands on one or more managed nodes.

Parameters:

  • instance_ids (Optional[InstanceIdList], default: None ) –

    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. Using Targets, 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 Run commands at scale in the Amazon Web Services Systems Manager User Guide.

  • targets (Optional[Targets], default: None ) –

    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. Using Targets, 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 Run commands at scale in the Amazon Web Services Systems Manager User Guide.

  • document_name (DocumentARN) –

    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 Sharing SSM documents in the Amazon Web Services Systems Manager User Guide.

    If you specify a document name or ARN that hasn't been shared with your account, you receive an InvalidDocument error.

  • document_version (Optional[DocumentVersion], default: None ) –

    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 (Optional[DocumentHash], default: None ) –

    The Sha256 or Sha1 hash created by the system when the document was created.

    Sha1 hashes have been deprecated.

  • document_hash_type (Optional[DocumentHashType], default: None ) –

    Sha256 or Sha1.

    Sha1 hashes have been deprecated.

  • timeout_seconds (Optional[TimeoutSeconds], default: None ) –

    If this time is reached and the command hasn't already started running, it won't run.

  • comment (Optional[Comment], default: None ) –

    User-specified information about the command, such as a brief description of what the command should do.

  • parameters (Optional[Parameters], default: None ) –

    The required and optional parameters specified in the document being run.

  • output_s3_region (Optional[S3Region], default: None ) –

    (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 (Optional[S3BucketName], default: None ) –

    The name of the S3 bucket where command execution responses should be stored.

  • output_s3_key_prefix (Optional[S3KeyPrefix], default: None ) –

    The directory structure within the S3 bucket where the responses should be stored.

  • max_concurrency (Optional[MaxConcurrency], default: None ) –

    (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 use MaxConcurrency, see Using concurrency controls in the Amazon Web Services Systems Manager User Guide.

  • max_errors (Optional[MaxErrors], default: None ) –

    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 is 0. For more information about how to use MaxErrors, see Using error controls in the Amazon Web Services Systems Manager User Guide.

  • service_role_arn (Optional[ServiceRole], default: None ) –

    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.

    This role must provide the sns:Publish permission for your notification topic. For information about creating and using this service role, see Monitoring Systems Manager status changes using Amazon SNS notifications in the Amazon Web Services Systems Manager User Guide.

  • notification_config (Optional[NotificationConfig], default: None ) –

    Configurations for sending notifications.

  • cloud_watch_output_config (Optional[CloudWatchOutputConfig], default: None ) –

    Enables Amazon Web Services Systems Manager to send Run Command output to Amazon CloudWatch Logs. Run Command is a tool in Amazon Web Services Systems Manager.

  • alarm_configuration (Optional[AlarmConfiguration], default: None ) –

    The CloudWatch alarm you want to apply to your command.

Raises:

  • DuplicateInstanceId –

    You can't specify a managed node ID in more than one association.

  • InternalServerError –

    An error occurred on the server side.

  • InvalidDocument –

    The specified SSM document doesn't exist.

  • InvalidDocumentVersion –

    The document version isn't valid or doesn't exist.

  • InvalidInstanceId –

    The following problems can cause this exception:

    • You don't have permission to access the managed node.

    • Amazon Web Services Systems Manager Agent (SSM Agent) isn't running. Verify that SSM Agent is running.

    • SSM Agent isn't registered with the SSM endpoint. Try reinstalling SSM Agent.

    • The managed node isn't in a valid state. Valid states are: Running, Pending, Stopped, and Stopping. Invalid states are: Shutting-down and Terminated.

  • InvalidNotificationConfig –

    One or more configuration items isn't valid. Verify that a valid Amazon Resource Name (ARN) was provided for an Amazon Simple Notification Service topic.

  • InvalidOutputFolder –

    The S3 bucket doesn't exist.

  • InvalidParameters –

    You must specify values for all required parameters in the Amazon Web Services Systems Manager document (SSM document). You can only supply values to parameters defined in the SSM document.

  • InvalidRole –

    The role name can't contain invalid characters. Also verify that you specified an IAM role for notifications that includes the required trust policy. For information about configuring the IAM role for Run Command notifications, see Monitoring Systems Manager status changes using Amazon SNS notifications in the Amazon Web Services Systems Manager User Guide.

  • MaxDocumentSizeExceeded –

    The size limit of a document is 64 KB.

  • UnsupportedPlatformType –

    The document doesn't support the platform type of the given managed node IDs. For example, you sent an document for a Windows managed node to a Linux node.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_ssm/_services/ssm.py
def send_command(
    self,
    document_name: "capo_ssm.types.document_arn.DocumentARN",
    *,
    config_overrides: Optional[SSMClientConfig] = None,
    instance_ids: Optional["capo_ssm.types.instance_id_list.InstanceIdList"] = None,
    targets: Optional["capo_ssm.types.targets.Targets"] = None,
    document_version: Optional[
        "capo_ssm.types.document_version.DocumentVersion"
    ] = None,
    document_hash: Optional["capo_ssm.types.document_hash.DocumentHash"] = None,
    document_hash_type: Optional[
        "capo_ssm.types.document_hash_type.DocumentHashType"
    ] = None,
    timeout_seconds: Optional[
        "capo_ssm.types.timeout_seconds.TimeoutSeconds"
    ] = None,
    comment: Optional["capo_ssm.types.comment.Comment"] = None,
    parameters: Optional["capo_ssm.types.parameters.Parameters"] = None,
    output_s3_region: Optional["capo_ssm.types.s3_region.S3Region"] = None,
    output_s3_bucket_name: Optional[
        "capo_ssm.types.s3_bucket_name.S3BucketName"
    ] = None,
    output_s3_key_prefix: Optional[
        "capo_ssm.types.s3_key_prefix.S3KeyPrefix"
    ] = None,
    max_concurrency: Optional[
        "capo_ssm.types.max_concurrency.MaxConcurrency"
    ] = None,
    max_errors: Optional["capo_ssm.types.max_errors.MaxErrors"] = None,
    service_role_arn: Optional["capo_ssm.types.service_role.ServiceRole"] = None,
    notification_config: Optional[
        "capo_ssm.types.notification_config.NotificationConfig"
    ] = None,
    cloud_watch_output_config: Optional[
        "capo_ssm.types.cloud_watch_output_config.CloudWatchOutputConfig"
    ] = None,
    alarm_configuration: Optional[
        "capo_ssm.types.alarm_configuration.AlarmConfiguration"
    ] = None,
) -> "capo_ssm.types.send_command_result.SendCommandResult":
    r"""<p>Runs commands on one or more managed nodes.</p>

    Args:
        instance_ids: <p>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.</p> <p>To target a larger number of managed nodes, or if you prefer not to list individual node IDs, we recommend using the <code>Targets</code> option instead. Using <code>Targets</code>, 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.</p> <p>For more information about how to use targets, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-multiple.html">Run commands at scale</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        targets: <p>An array of search criteria that targets managed nodes using a <code>Key,Value</code> 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. Using <code>Targets</code>, which accepts tag key-value pairs to identify managed nodes, you can send a command to tens, hundreds, or thousands of nodes at once.</p> <p>To send a command to a smaller number of managed nodes, you can use the <code>InstanceIds</code> option instead.</p> <p>For more information about how to use targets, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-multiple.html">Run commands at scale</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        document_name: <p>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 <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-using-shared.html">Sharing SSM documents</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p> <note> <p>If you specify a document name or ARN that hasn't been shared with your account, you receive an <code>InvalidDocument</code> error. </p> </note>
        document_version: <p>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:</p> <p>--document-version "\$DEFAULT"</p> <p>--document-version "\$LATEST"</p> <p>--document-version "3"</p>
        document_hash: <p>The Sha256 or Sha1 hash created by the system when the document was created. </p> <note> <p>Sha1 hashes have been deprecated.</p> </note>
        document_hash_type: <p>Sha256 or Sha1.</p> <note> <p>Sha1 hashes have been deprecated.</p> </note>
        timeout_seconds: <p>If this time is reached and the command hasn't already started running, it won't run.</p>
        comment: <p>User-specified information about the command, such as a brief description of what the command should do.</p>
        parameters: <p>The required and optional parameters specified in the document being run.</p>
        output_s3_region: <p>(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.</p>
        output_s3_bucket_name: <p>The name of the S3 bucket where command execution responses should be stored.</p>
        output_s3_key_prefix: <p>The directory structure within the S3 bucket where the responses should be stored.</p>
        max_concurrency: <p>(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 <code>50</code>. For more information about how to use <code>MaxConcurrency</code>, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-multiple.html#send-commands-velocity">Using concurrency controls</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        max_errors: <p>The maximum number of errors allowed without the command failing. When the command fails one more time beyond the value of <code>MaxErrors</code>, the systems stops sending the command to additional targets. You can specify a number like 10 or a percentage like 10%. The default value is <code>0</code>. For more information about how to use <code>MaxErrors</code>, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-multiple.html#send-commands-maxerrors">Using error controls</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        service_role_arn: <p>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.</p> <p>This role must provide the <code>sns:Publish</code> permission for your notification topic. For information about creating and using this service role, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/monitoring-sns-notifications.html">Monitoring Systems Manager status changes using Amazon SNS notifications</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        notification_config: <p>Configurations for sending notifications.</p>
        cloud_watch_output_config: <p>Enables Amazon Web Services Systems Manager to send Run Command output to Amazon CloudWatch Logs. Run Command is a tool in Amazon Web Services Systems Manager.</p>
        alarm_configuration: <p>The CloudWatch alarm you want to apply to your command.</p>

    Raises:
        capo_ssm.errors.duplicate_instance_id.DuplicateInstanceId: <p>You can't specify a managed node ID in more than one association.</p>
        capo_ssm.errors.internal_server_error.InternalServerError: <p>An error occurred on the server side.</p>
        capo_ssm.errors.invalid_document.InvalidDocument: <p>The specified SSM document doesn't exist.</p>
        capo_ssm.errors.invalid_document_version.InvalidDocumentVersion: <p>The document version isn't valid or doesn't exist.</p>
        capo_ssm.errors.invalid_instance_id.InvalidInstanceId: <p>The following problems can cause this exception:</p> <ul> <li> <p>You don't have permission to access the managed node.</p> </li> <li> <p>Amazon Web Services Systems Manager Agent (SSM Agent) isn't running. Verify that SSM Agent is running.</p> </li> <li> <p>SSM Agent isn't registered with the SSM endpoint. Try reinstalling SSM Agent.</p> </li> <li> <p>The managed node isn't in a valid state. Valid states are: <code>Running</code>, <code>Pending</code>, <code>Stopped</code>, and <code>Stopping</code>. Invalid states are: <code>Shutting-down</code> and <code>Terminated</code>.</p> </li> </ul>
        capo_ssm.errors.invalid_notification_config.InvalidNotificationConfig: <p>One or more configuration items isn't valid. Verify that a valid Amazon Resource Name (ARN) was provided for an Amazon Simple Notification Service topic.</p>
        capo_ssm.errors.invalid_output_folder.InvalidOutputFolder: <p>The S3 bucket doesn't exist.</p>
        capo_ssm.errors.invalid_parameters.InvalidParameters: <p>You must specify values for all required parameters in the Amazon Web Services Systems Manager document (SSM document). You can only supply values to parameters defined in the SSM document.</p>
        capo_ssm.errors.invalid_role.InvalidRole: <p>The role name can't contain invalid characters. Also verify that you specified an IAM role for notifications that includes the required trust policy. For information about configuring the IAM role for Run Command notifications, see <a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/monitoring-sns-notifications.html">Monitoring Systems Manager status changes using Amazon SNS notifications</a> in the <i>Amazon Web Services Systems Manager User Guide</i>.</p>
        capo_ssm.errors.max_document_size_exceeded.MaxDocumentSizeExceeded: <p>The size limit of a document is 64 KB.</p>
        capo_ssm.errors.unsupported_platform_type.UnsupportedPlatformType: <p>The document doesn't support the platform type of the given managed node IDs. For example, you sent an document for a Windows managed node to a Linux node.</p>
        capo_ssm.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_ssm.types.send_command_request.SendCommandRequest]",
    ) -> OperationResponse["capo_ssm.types.send_command_result.SendCommandResult"]:
        import capo_ssm._operations.amazon_ssm.send_command

        output, http_response = (
            capo_ssm._operations.amazon_ssm.send_command.send_command(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_ssm.types.send_command_request.SendCommandRequest",
    ) -> dict[str, Any]:
        import capo_ssm.types.send_command_request

        return capo_ssm.types.send_command_request.redact_sensitive(input_)

    def _redact_output(
        output: "capo_ssm.types.send_command_result.SendCommandResult",
    ) -> dict[str, Any]:
        import capo_ssm.types.send_command_result

        return capo_ssm.types.send_command_result.redact_sensitive(output)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "SendCommand", redact_input=_redact_input, redact_output=_redact_output
        ),
    )
    input_: capo_ssm.types.send_command_request.SendCommandRequest = {
        "document_name": document_name
    }
    if instance_ids is not None:
        input_["instance_ids"] = instance_ids
    if targets is not None:
        input_["targets"] = targets
    if document_version is not None:
        input_["document_version"] = document_version
    if document_hash is not None:
        input_["document_hash"] = document_hash
    if document_hash_type is not None:
        input_["document_hash_type"] = document_hash_type
    if timeout_seconds is not None:
        input_["timeout_seconds"] = timeout_seconds
    if comment is not None:
        input_["comment"] = comment
    if parameters is not None:
        input_["parameters"] = parameters
    if output_s3_region is not None:
        input_["output_s3_region"] = output_s3_region
    if output_s3_bucket_name is not None:
        input_["output_s3_bucket_name"] = output_s3_bucket_name
    if output_s3_key_prefix is not None:
        input_["output_s3_key_prefix"] = output_s3_key_prefix
    if max_concurrency is not None:
        input_["max_concurrency"] = max_concurrency
    if max_errors is not None:
        input_["max_errors"] = max_errors
    if service_role_arn is not None:
        input_["service_role_arn"] = service_role_arn
    if notification_config is not None:
        input_["notification_config"] = notification_config
    if cloud_watch_output_config is not None:
        input_["cloud_watch_output_config"] = cloud_watch_output_config
    if alarm_configuration is not None:
        input_["alarm_configuration"] = alarm_configuration

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output