Table of Contents
EC2InstanceConnect.
Client
¶A low-level client representing AWS EC2 Instance Connect
Amazon EC2 Instance Connect enables system administrators to publish one-time use SSH public keys to EC2, providing users a simple and secure way to connect to their instances.
import boto3
client = boto3.client('ec2-instance-connect')
These are the available methods:
can_paginate()
close()
get_paginator()
get_waiter()
send_serial_console_ssh_public_key()
send_ssh_public_key()
can_paginate
(operation_name)¶Check if an operation can be paginated.
create_foo
, and you'd normally invoke the
operation as client.create_foo(**kwargs)
, if the
create_foo
operation can be paginated, you can use the
call client.get_paginator("create_foo")
.True
if the operation can be paginated,
False
otherwise.close
()¶Closes underlying endpoint connections.
get_paginator
(operation_name)¶Create a paginator for an operation.
create_foo
, and you'd normally invoke the
operation as client.create_foo(**kwargs)
, if the
create_foo
operation can be paginated, you can use the
call client.get_paginator("create_foo")
.client.can_paginate
method to
check if an operation is pageable.get_waiter
(waiter_name)¶Returns an object that can wait for some condition.
send_serial_console_ssh_public_key
(**kwargs)¶Pushes an SSH public key to the specified EC2 instance. The key remains for 60 seconds, which gives you 60 seconds to establish a serial console connection to the instance using SSH. For more information, see EC2 Serial Console in the Amazon EC2 User Guide .
See also: AWS API Documentation
Request Syntax
response = client.send_serial_console_ssh_public_key(
InstanceId='string',
SerialPort=123,
SSHPublicKey='string'
)
[REQUIRED]
The ID of the EC2 instance.
The serial port of the EC2 instance. Currently only port 0 is supported.
Default: 0
[REQUIRED]
The public key material. To use the public key, you must have the matching private key. For information about the supported key formats and lengths, see Requirements for key pairs in the Amazon EC2 User Guide .
dict
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.SerialConsoleAccessDisabledException
EC2InstanceConnect.Client.exceptions.InvalidArgsException
EC2InstanceConnect.Client.exceptions.ServiceException
EC2InstanceConnect.Client.exceptions.ThrottlingException
EC2InstanceConnect.Client.exceptions.EC2InstanceNotFoundException
EC2InstanceConnect.Client.exceptions.EC2InstanceTypeInvalidException
EC2InstanceConnect.Client.exceptions.SerialConsoleSessionLimitExceededException
EC2InstanceConnect.Client.exceptions.SerialConsoleSessionUnavailableException
EC2InstanceConnect.Client.exceptions.EC2InstanceStateInvalidException
EC2InstanceConnect.Client.exceptions.EC2InstanceUnavailableException
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'
)
[REQUIRED]
The ID of the EC2 instance.
[REQUIRED]
The OS user on the EC2 instance for whom the key can be used to authenticate.
[REQUIRED]
The public key material. To use the public key, you must have the matching private key.
dict
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': {
'...': '...',
},
}
The available paginators are: