:doc:`EC2 <../../ec2>` / Client / associate_iam_instance_profile

******************************
associate_iam_instance_profile
******************************



.. py:method:: EC2.Client.associate_iam_instance_profile(**kwargs)

  

  Associates an IAM instance profile with a running or stopped instance. You cannot associate more than one IAM instance profile with an instance.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/ec2-2016-11-15/AssociateIamInstanceProfile>`_  


  **Request Syntax**
  ::

    response = client.associate_iam_instance_profile(
        IamInstanceProfile={
            'Arn': 'string',
            'Name': 'string'
        },
        InstanceId='string'
    )
    
  :type IamInstanceProfile: dict
  :param IamInstanceProfile: **[REQUIRED]** 

    The IAM instance profile.

    

  
    - **Arn** *(string) --* 

      The Amazon Resource Name (ARN) of the instance profile.

      

    
    - **Name** *(string) --* 

      The name of the instance profile.

      

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

    The ID of the instance.

    

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

    
    ::

      {
          'IamInstanceProfileAssociation': {
              'AssociationId': 'string',
              'InstanceId': 'string',
              'IamInstanceProfile': {
                  'Arn': 'string',
                  'Id': 'string'
              },
              'State': 'associating'|'associated'|'disassociating'|'disassociated',
              'Timestamp': datetime(2015, 1, 1)
          }
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **IamInstanceProfileAssociation** *(dict) --* 

        Information about the IAM instance profile association.

        
        

        - **AssociationId** *(string) --* 

          The ID of the association.

          
        

        - **InstanceId** *(string) --* 

          The ID of the instance.

          
        

        - **IamInstanceProfile** *(dict) --* 

          The IAM instance profile.

          
          

          - **Arn** *(string) --* 

            The Amazon Resource Name (ARN) of the instance profile.

            
          

          - **Id** *(string) --* 

            The ID of the instance profile.

            
      
        

        - **State** *(string) --* 

          The state of the association.

          
        

        - **Timestamp** *(datetime) --* 

          The time the IAM instance profile was associated with the instance.

          
    
  

  **Examples**

  This example associates an IAM instance profile named admin-role with the specified instance.
  ::

    response = client.associate_iam_instance_profile(
        IamInstanceProfile={
            'Name': 'admin-role',
        },
        InstanceId='i-123456789abcde123',
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        'IamInstanceProfileAssociation': {
            'AssociationId': 'iip-assoc-0e7736511a163c209',
            'IamInstanceProfile': {
                'Arn': 'arn:aws:iam::123456789012:instance-profile/admin-role',
                'Id': 'AIPAJBLK7RKJKWDXVHIEC',
            },
            'InstanceId': 'i-123456789abcde123',
            'State': 'associating',
        },
        'ResponseMetadata': {
            '...': '...',
        },
    }

  