:doc:`Batch <../../batch>` / Client / cancel_job

**********
cancel_job
**********



.. py:method:: Batch.Client.cancel_job(**kwargs)

  

  Cancels a job in an Batch job queue. 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 canceled after all dependency jobs are completed. Therefore, it may 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 canceled when all child jobs are completed.

    

   

  Jobs that progressed to the ``STARTING`` or ``RUNNING`` state aren't canceled. However, the API operation still succeeds, even if no job is canceled. These jobs must be terminated with the  TerminateJob operation.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/batch-2016-08-10/CancelJob>`_  


  **Request Syntax**
  ::

    response = client.cancel_job(
        jobId='string',
        reason='string'
    )
    
  :type jobId: string
  :param jobId: **[REQUIRED]** 

    The Batch job ID of the job to cancel.

    

  
  :type reason: string
  :param reason: **[REQUIRED]** 

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

     

    This parameter has as limit of 1024 characters.

    

  
  
  :rtype: dict
  :returns: 
    
    **Response Syntax**

    
    ::

      {}
      
    **Response Structure**

    

    - *(dict) --* 
  
  **Exceptions**
  
  *   :py:class:`Batch.Client.exceptions.ClientException`

  
  *   :py:class:`Batch.Client.exceptions.ServerException`

  

  **Examples**

  This example cancels a job with the specified job ID.
  ::

    response = client.cancel_job(
        jobId='1d828f65-7a4d-42e8-996d-3b900ed59dc4',
        reason='Cancelling job.',
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        'ResponseMetadata': {
            '...': '...',
        },
    }

  