Skip to content

terminate_jobs

terminate_jobs(
    *,
    config_overrides: Optional[BatchClientConfig] = None,
    jobs: Optional[StringList] = None,
    reason: Optional[String] = None,
) -> TerminateJobsResponse

Terminates up to 50 jobs in a job queue. This is a bulk version of TerminateJob. Jobs that are in the STARTING or RUNNING state are terminated, which causes them to transition to FAILED. Jobs that have not progressed to the STARTING state are cancelled.

Batch reports the result for each job individually in the response. Jobs that were processed successfully are reported in the successful list. Jobs that encountered errors are reported in the errors list. The response returns an HTTP status code of 200 even when some jobs encountered errors, so check the errors list. Jobs that can't be found are treated as successfully processed.

This operation requires batch:TerminateJob permission for each job in the request. There is no separate batch:TerminateJobs IAM action. If a caller's IAM policy grants batch:TerminateJob, they can use both the singular TerminateJob and bulk TerminateJobs operations.

Parameters:

  • jobs (Optional[StringList], default: None ) –

    An array of up to 50 Batch job IDs of the jobs to terminate.

  • reason (Optional[String], default: None ) –

    A message to attach to the job that explains the reason for terminating it. This message is returned by future DescribeJobs operations on the job. It is also recorded in the Batch activity logs.

    This parameter has a limit of 1024 characters.

Raises:

  • ClientException –

    These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.

  • ServerException –

    These errors are usually caused by a server issue.

  • UnknownServiceError –

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

Examples:

To terminate multiple jobs This example terminates the jobs with the specified job IDs.

>>> client.terminate_jobs(jobs=['61e743ed-35e4-48da-b2de-5c8333821c84', 'b3d0f26e-6d3a-4a5b-9c2e-7f4a1b2c3d4e'], reason='Terminating jobs.')
Source code in docs_src/capo_batch/_services/batch.py
def terminate_jobs(
    self,
    *,
    config_overrides: Optional[BatchClientConfig] = None,
    jobs: Optional["capo_batch.types.string_list.StringList"] = None,
    reason: Optional["capo_batch.types.string.String"] = None,
) -> "capo_batch.types.terminate_jobs_response.TerminateJobsResponse":
    """<p>Terminates up to 50 jobs in a job queue. This is a bulk version of <a>TerminateJob</a>. Jobs that are in the <code>STARTING</code> or <code>RUNNING</code> state are terminated, which causes them to transition to <code>FAILED</code>. Jobs that have not progressed to the <code>STARTING</code> state are cancelled.</p> <p>Batch reports the result for each job individually in the response. Jobs that were processed successfully are reported in the <code>successful</code> list. Jobs that encountered errors are reported in the <code>errors</code> list. The response returns an HTTP status code of <code>200</code> even when some jobs encountered errors, so check the <code>errors</code> list. Jobs that can't be found are treated as successfully processed.</p> <important> <p>This operation requires <code>batch:TerminateJob</code> permission for each job in the request. There is no separate <code>batch:TerminateJobs</code> IAM action. If a caller's IAM policy grants <code>batch:TerminateJob</code>, they can use both the singular <a>TerminateJob</a> and bulk <code>TerminateJobs</code> operations.</p> </important>

    Args:
        jobs: <p>An array of up to 50 Batch job IDs of the jobs to terminate.</p>
        reason: <p>A message to attach to the job that explains the reason for terminating it. This message is returned by future <a>DescribeJobs</a> operations on the job. It is also recorded in the Batch activity logs.</p> <p>This parameter has a limit of 1024 characters.</p>

    Raises:
        capo_batch.errors.client_exception.ClientException: <p>These errors are usually caused by a client action. One example cause is using an action or resource on behalf of a user that doesn't have permissions to use the action or resource. Another cause is specifying an identifier that's not valid.</p>
        capo_batch.errors.server_exception.ServerException: <p>These errors are usually caused by a server issue.</p>
        capo_batch.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To terminate multiple jobs
        This example terminates the jobs with the specified job IDs.

        >>> client.terminate_jobs(jobs=['61e743ed-35e4-48da-b2de-5c8333821c84', 'b3d0f26e-6d3a-4a5b-9c2e-7f4a1b2c3d4e'], reason='Terminating jobs.')
    """

    def _handler(
        req: "OperationRequest[capo_batch.types.terminate_jobs_request.TerminateJobsRequest]",
    ) -> OperationResponse[
        "capo_batch.types.terminate_jobs_response.TerminateJobsResponse"
    ]:
        import capo_batch._operations.aws_batch_v20160810.terminate_jobs

        output, http_response = (
            capo_batch._operations.aws_batch_v20160810.terminate_jobs.terminate_jobs(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("TerminateJobs")
    )
    input_: capo_batch.types.terminate_jobs_request.TerminateJobsRequest = {}
    if jobs is not None:
        input_["jobs"] = jobs
    if reason is not None:
        input_["reason"] = reason

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