:doc:`IAM <../../iam>` / Client / delete_role

***********
delete_role
***********



.. py:method:: IAM.Client.delete_role(**kwargs)

  

  Deletes the specified role. Unlike the Amazon Web Services Management Console, when you delete a role programmatically, you must delete the items attached to the role manually, or the deletion fails. For more information, see `Deleting an IAM role <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_manage_delete.html#roles-managingrole-deleting-cli>`__. Before attempting to delete a role, remove the following attached items:

   

  
  * Inline policies ( `DeleteRolePolicy <https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteRolePolicy.html>`__)
   
  * Attached managed policies ( `DetachRolePolicy <https://docs.aws.amazon.com/IAM/latest/APIReference/API_DetachRolePolicy.html>`__)
   
  * Instance profile ( `RemoveRoleFromInstanceProfile <https://docs.aws.amazon.com/IAM/latest/APIReference/API_RemoveRoleFromInstanceProfile.html>`__)
   
  * Optional – Delete instance profile after detaching from role for resource clean up ( `DeleteInstanceProfile <https://docs.aws.amazon.com/IAM/latest/APIReference/API_DeleteInstanceProfile.html>`__)
  

   

  .. warning::

     

    Make sure that you do not have any Amazon EC2 instances running with the role you are about to delete. Deleting a role or instance profile that is associated with a running instance will break any applications running on the instance.

    

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/iam-2010-05-08/DeleteRole>`_  


  **Request Syntax**
  ::

    response = client.delete_role(
        RoleName='string'
    )
    
  :type RoleName: string
  :param RoleName: **[REQUIRED]** 

    The name of the role to delete.

     

    This parameter allows (through its `regex pattern <http://wikipedia.org/wiki/regex>`__) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

    

  
  
  :returns: None
  **Exceptions**
  
  *   :py:class:`IAM.Client.exceptions.NoSuchEntityException`

  
  *   :py:class:`IAM.Client.exceptions.DeleteConflictException`

  
  *   :py:class:`IAM.Client.exceptions.LimitExceededException`

  
  *   :py:class:`IAM.Client.exceptions.UnmodifiableEntityException`

  
  *   :py:class:`IAM.Client.exceptions.ConcurrentModificationException`

  
  *   :py:class:`IAM.Client.exceptions.ServiceFailureException`

  

  **Examples**

  The following command removes the role named Test-Role.
  ::

    response = client.delete_role(
        RoleName='Test-Role',
    )
    
    print(response)

  
  Expected Output:
  ::

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

  