send_ssh_public_key

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 in the Amazon EC2 User Guide .

See also: AWS API Documentation

Request Syntax

response = client.send_ssh_public_key(
    InstanceId='string',
    InstanceOSUser='string',
    SSHPublicKey='string',
    AvailabilityZone='string'
)
Parameters
  • InstanceId (string) --

    [REQUIRED]

    The ID of the EC2 instance.

  • InstanceOSUser (string) --

    [REQUIRED]

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

  • SSHPublicKey (string) --

    [REQUIRED]

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

  • AvailabilityZone (string) -- The Availability Zone in which the EC2 instance was launched.
Return type

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

  • EC2InstanceConnect.Client.exceptions.AuthException
  • EC2InstanceConnect.Client.exceptions.InvalidArgsException
  • EC2InstanceConnect.Client.exceptions.ServiceException
  • EC2InstanceConnect.Client.exceptions.ThrottlingException
  • EC2InstanceConnect.Client.exceptions.EC2InstanceNotFoundException
  • EC2InstanceConnect.Client.exceptions.EC2InstanceStateInvalidException
  • 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': {
        '...': '...',
    },
}