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

***************
get_role_policy
***************



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

  

  Retrieves the specified inline policy document that is embedded with the specified IAM role.

   

  .. note::

    

    Policies returned by this operation are URL-encoded compliant with `RFC 3986 <https://tools.ietf.org/html/rfc3986>`__. You can use a URL decoding method to convert the policy back to plain JSON text. For example, if you use Java, you can use the ``decode`` method of the ``java.net.URLDecoder`` utility class in the Java SDK. Other languages and SDKs provide similar functionality, and some SDKs do this decoding automatically.

    

   

  An IAM role can also have managed policies attached to it. To retrieve a managed policy document that is attached to a role, use `GetPolicy <https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicy.html>`__ to determine the policy's default version, then use `GetPolicyVersion <https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetPolicyVersion.html>`__ to retrieve the policy document.

   

  For more information about policies, see `Managed policies and inline policies <https://docs.aws.amazon.com/IAM/latest/UserGuide/policies-managed-vs-inline.html>`__ in the *IAM User Guide*.

   

  For more information about roles, see `IAM roles <https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html>`__ in the *IAM User Guide*.

  

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


  **Request Syntax**
  ::

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

    The name of the role associated with the policy.

     

    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: _+=,.@-

    

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

    The name of the policy document to get.

     

    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: _+=,.@-

    

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

    
    ::

      {
          'RoleName': 'string',
          'PolicyName': 'string',
          'PolicyDocument': 'string'
      }
      
    **Response Structure**

    

    - *(dict) --* 

      Contains the response to a successful `GetRolePolicy <https://docs.aws.amazon.com/IAM/latest/APIReference/API_GetRolePolicy.html>`__ request.

      
      

      - **RoleName** *(string) --* 

        The role the policy is associated with.

        
      

      - **PolicyName** *(string) --* 

        The name of the policy.

        
      

      - **PolicyDocument** *(string) --* 

        The policy document.

         

        IAM stores policies in JSON format. However, resources that were created using CloudFormation templates can be formatted in YAML. CloudFormation always converts a YAML policy to JSON format before submitting it to IAM.

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

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

  