:doc:`EC2InstanceConnect <../../ec2-instance-connect>` / Client / send_ssh_public_key

*******************
send_ssh_public_key
*******************



.. py:method:: EC2InstanceConnect.Client.send_ssh_public_key(**kwargs)

  

  Pushes an SSH public key to the specified EC2 instance for use by the specified user. The key remains for 60 seconds. For more information, see `Connect to your Linux instance using EC2 Instance Connect <https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Connect-using-EC2-Instance-Connect.html>`__ in the *Amazon EC2 User Guide*.

  

  See also: `AWS API Documentation <https://docs.aws.amazon.com/goto/WebAPI/ec2-instance-connect-2018-04-02/SendSSHPublicKey>`_  


  **Request Syntax**
  ::

    response = client.send_ssh_public_key(
        InstanceId='string',
        InstanceOSUser='string',
        SSHPublicKey='string',
        AvailabilityZone='string'
    )
    
  :type InstanceId: string
  :param InstanceId: **[REQUIRED]** 

    The ID of the EC2 instance.

    

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

    The OS user on the EC2 instance for whom the key can be used to authenticate.

    

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

    The public key material. To use the public key, you must have the matching private key.

    

  
  :type AvailabilityZone: string
  :param AvailabilityZone: 

    The Availability Zone in which the EC2 instance was launched.

    

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

    
    ::

      {
          'RequestId': 'string',
          'Success': True|False
      }
      
    **Response Structure**

    

    - *(dict) --* 
      

      - **RequestId** *(string) --* 

        The ID of the request. Please provide this ID when contacting AWS Support for assistance.

        
      

      - **Success** *(boolean) --* 

        Is true if the request succeeds and an error otherwise.

        
  
  **Exceptions**
  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.AuthException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.InvalidArgsException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.ServiceException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.ThrottlingException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.EC2InstanceNotFoundException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.EC2InstanceStateInvalidException`

  
  *   :py:class:`EC2InstanceConnect.Client.exceptions.EC2InstanceUnavailableException`

  

  **Examples**

  The following example pushes a sample SSH public key to the EC2 instance i-abcd1234 in AZ us-west-2b for use by the instance OS user ec2-user.
  ::

    response = client.send_ssh_public_key(
        # The zone where the instance was launched
        AvailabilityZone='us-west-2a',
        # The instance ID to publish the key to.
        InstanceId='i-abcd1234',
        # This should be the user you wish to be when ssh-ing to the instance (eg, ec2-user@[instance IP])
        InstanceOSUser='ec2-user',
        # This should be in standard OpenSSH format (ssh-rsa [key body])
        SSHPublicKey='ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3FlHqj2eqCdrGHuA6dRjfZXQ4HX5lXEIRHaNbxEwE5Te7xNF7StwhrDtiV7IdT5fDqbRyGw/szPj3xGkNTVoElCZ2dDFb2qYZ1WLIpZwj/UhO9l2mgfjR56UojjQut5Jvn2KZ1OcyrNO0J83kCaJCV7JoVbXY79FBMUccYNY45zmv9+1FMCfY6i2jdIhwR6+yLk8oubL8lIPyq7X+6b9S0yKCkB7Peml1DvghlybpAIUrC9vofHt6XP4V1i0bImw1IlljQS+DUmULRFSccATDscCX9ajnj7Crhm0HAZC0tBPXpFdHkPwL3yzYo546SCS9LKEwz62ymxxbL9k7h09t',
    )
    
    print(response)

  
  Expected Output:
  ::

    {
        # This request ID should be provided when contacting AWS Support.
        'RequestId': 'abcd1234-abcd-1234-abcd-1234abcd1234',
        # Should be true if the service does not return an error response.
        'Success': True,
        'ResponseMetadata': {
            '...': '...',
        },
    }

  