Batch / Client / cancel_jobs

cancel_jobs

Batch.Client.cancel_jobs(**kwargs)

Cancels up to 50 jobs in an Batch job queue. This is a bulk version of CancelJob. Jobs that are in a SUBMITTED, PENDING, or RUNNABLE state are cancelled and the job status is updated to FAILED.

Note

A PENDING job is cancelled after all dependency jobs are completed. Therefore, it might take longer than expected to cancel a job in PENDING status.

When you try to cancel an array parent job in PENDING, Batch attempts to cancel all child jobs. The array parent job is cancelled when all child jobs are completed.

Jobs that progressed to the STARTING or RUNNING state aren’t cancelled. These jobs must be terminated with the TerminateJob or TerminateJobs operation.

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.

See also: AWS API Documentation

Request Syntax

response = client.cancel_jobs(
    jobs=[
        'string',
    ],
    reason='string'
)
Parameters:
  • jobs (list) –

    [REQUIRED]

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

    • (string) –

  • reason (string) –

    [REQUIRED]

    A message to attach to the job that explains the reason for cancelling 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.

Return type:

dict

Returns:

Response Syntax

{
    'successful': [
        'string',
    ],
    'errors': [
        {
            'job': 'string',
            'code': 'string',
            'message': 'string'
        },
    ]
}

Response Structure

  • (dict) –

    The result of a CancelJobs request, including the jobs whose cancellation request was accepted and the errors for jobs that couldn’t be cancelled.

    • successful (list) –

      A list of the job IDs whose cancellation request was accepted.

      • (string) –

    • errors (list) –

      A list of CancelJobsErrorDetail items, one for each job that couldn’t be cancelled. Each item includes the job ID along with a code and message that describe why the job wasn’t cancelled.

      • (dict) –

        An object that contains the details of a job that couldn’t be cancelled by a CancelJobs operation.

        • job (string) –

          The Batch job ID of the job that couldn’t be cancelled.

        • code (string) –

          An error code that identifies the reason the job couldn’t be cancelled. Valid values are:

          • ValidationException – A job identifier in the request is malformed or isn’t valid.

          • ClientException – The request failed because of a client error.

          • ThrottlingException – The request was throttled. Retry the request.

          • ServerException – An internal error occurred. Retry the request.

          • AccessDenied – The caller isn’t authorized to perform the action on the specified job.

        • message (string) –

          A message that describes the reason the job couldn’t be cancelled.

Exceptions

  • Batch.Client.exceptions.ClientException

  • Batch.Client.exceptions.ServerException