AWS EC2 Instance Connect 2018-04-02
- Client: Aws\EC2InstanceConnect\EC2InstanceConnectClient
- Service ID: ec2-instance-connect
- Version: 2018-04-02
This page describes the parameters and results for the operations of the AWS EC2 Instance Connect (2018-04-02), and shows how to use the Aws\EC2InstanceConnect\EC2InstanceConnectClient object to call the described operations. This documentation is specific to the 2018-04-02 API version of the service.
Operation Summary
Each of the following operations can be created from a client using
$client->getCommand('CommandName')
, where "CommandName" is the
name of one of the following operations. Note: a command is a value that
encapsulates an operation and the parameters used to create an HTTP request.
You can also create and send a command immediately using the magic methods
available on a client object: $client->commandName(/* parameters */)
.
You can send the command asynchronously (returning a promise) by appending the
word "Async" to the operation name: $client->commandNameAsync(/* parameters */)
.
- SendSSHPublicKey ( array $params = [] )
Pushes an SSH public key to the specified EC2 instance for use by the specified user.
- SendSerialConsoleSSHPublicKey ( array $params = [] )
Pushes an SSH public key to the specified EC2 instance.
Operations
SendSSHPublicKey
$result = $client->sendSSHPublicKey
([/* ... */]); $promise = $client->sendSSHPublicKeyAsync
([/* ... */]);
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.
Parameter Syntax
$result = $client->sendSSHPublicKey([ 'AvailabilityZone' => '<string>', 'InstanceId' => '<string>', // REQUIRED 'InstanceOSUser' => '<string>', // REQUIRED 'SSHPublicKey' => '<string>', // REQUIRED ]);
Parameter Details
Members
- AvailabilityZone
-
- Type: string
The Availability Zone in which the EC2 instance was launched.
- InstanceId
-
- Required: Yes
- Type: string
The ID of the EC2 instance.
- InstanceOSUser
-
- Required: Yes
- Type: string
The OS user on the EC2 instance for whom the key can be used to authenticate.
- SSHPublicKey
-
- Required: Yes
- Type: string
The public key material. To use the public key, you must have the matching private key.
Result Syntax
[ 'RequestId' => '<string>', 'Success' => true || false, ]
Result Details
Members
Errors
-
Either your AWS credentials are not valid or you do not have access to the EC2 instance.
-
One of the parameters is not valid.
-
The service encountered an error. Follow the instructions in the error message and try again.
-
The requests were made too frequently and have been throttled. Wait a while and try again. To increase the limit on your request frequency, contact AWS Support.
-
The specified instance was not found.
-
EC2InstanceStateInvalidException:
Unable to connect because the instance is not in a valid state. Connecting to a stopped or terminated instance is not supported. If the instance is stopped, start your instance, and try to connect again.
Examples
Example 1: To push an SSH key to an EC2 instance
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.
$result = $client->sendSSHPublicKey([ 'AvailabilityZone' => 'us-west-2a', // The zone where the instance was launched 'InstanceId' => 'i-abcd1234', // The instance ID to publish the key to. 'InstanceOSUser' => 'ec2-user', // This should be the user you wish to be when ssh-ing to the instance (eg, ec2-user@[instance IP]) 'SSHPublicKey' => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC3FlHqj2eqCdrGHuA6dRjfZXQ4HX5lXEIRHaNbxEwE5Te7xNF7StwhrDtiV7IdT5fDqbRyGw/szPj3xGkNTVoElCZ2dDFb2qYZ1WLIpZwj/UhO9l2mgfjR56UojjQut5Jvn2KZ1OcyrNO0J83kCaJCV7JoVbXY79FBMUccYNY45zmv9+1FMCfY6i2jdIhwR6+yLk8oubL8lIPyq7X+6b9S0yKCkB7Peml1DvghlybpAIUrC9vofHt6XP4V1i0bImw1IlljQS+DUmULRFSccATDscCX9ajnj7Crhm0HAZC0tBPXpFdHkPwL3yzYo546SCS9LKEwz62ymxxbL9k7h09t', // This should be in standard OpenSSH format (ssh-rsa [key body]) ]);
Result syntax:
[ 'RequestId' => 'abcd1234-abcd-1234-abcd-1234abcd1234', // This request ID should be provided when contacting AWS Support. 'Success' => 1, // Should be true if the service does not return an error response. ]
SendSerialConsoleSSHPublicKey
$result = $client->sendSerialConsoleSSHPublicKey
([/* ... */]); $promise = $client->sendSerialConsoleSSHPublicKeyAsync
([/* ... */]);
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.
Parameter Syntax
$result = $client->sendSerialConsoleSSHPublicKey([ 'InstanceId' => '<string>', // REQUIRED 'SSHPublicKey' => '<string>', // REQUIRED 'SerialPort' => <integer>, ]);
Parameter Details
Members
- InstanceId
-
- Required: Yes
- Type: string
The ID of the EC2 instance.
- SSHPublicKey
-
- Required: Yes
- Type: string
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.
- SerialPort
-
- Type: int
The serial port of the EC2 instance. Currently only port 0 is supported.
Default: 0
Result Syntax
[ 'RequestId' => '<string>', 'Success' => true || false, ]
Result Details
Members
Errors
-
Either your AWS credentials are not valid or you do not have access to the EC2 instance.
-
SerialConsoleAccessDisabledException:
Your account is not authorized to use the EC2 Serial Console. To authorize your account, run the EnableSerialConsoleAccess API. For more information, see EnableSerialConsoleAccess in the Amazon EC2 API Reference.
-
One of the parameters is not valid.
-
The service encountered an error. Follow the instructions in the error message and try again.
-
The requests were made too frequently and have been throttled. Wait a while and try again. To increase the limit on your request frequency, contact AWS Support.
-
The specified instance was not found.
-
EC2InstanceTypeInvalidException:
The instance type is not supported for connecting via the serial console. Only Nitro instance types are currently supported.
-
SerialConsoleSessionLimitExceededException:
The instance currently has 1 active serial console session. Only 1 session is supported at a time.
-
SerialConsoleSessionUnavailableException:
Unable to start a serial console session. Please try again.
-
EC2InstanceStateInvalidException:
Unable to connect because the instance is not in a valid state. Connecting to a stopped or terminated instance is not supported. If the instance is stopped, start your instance, and try to connect again.
Shapes
AuthException
Description
Either your AWS credentials are not valid or you do not have access to the EC2 instance.
Members
EC2InstanceNotFoundException
EC2InstanceStateInvalidException
Description
Unable to connect because the instance is not in a valid state. Connecting to a stopped or terminated instance is not supported. If the instance is stopped, start your instance, and try to connect again.
Members
EC2InstanceTypeInvalidException
Description
The instance type is not supported for connecting via the serial console. Only Nitro instance types are currently supported.
Members
InvalidArgsException
SerialConsoleAccessDisabledException
Description
Your account is not authorized to use the EC2 Serial Console. To authorize your account, run the EnableSerialConsoleAccess API. For more information, see EnableSerialConsoleAccess in the Amazon EC2 API Reference.
Members
SerialConsoleSessionLimitExceededException
Description
The instance currently has 1 active serial console session. Only 1 session is supported at a time.
Members
SerialConsoleSessionUnavailableException
Description
Unable to start a serial console session. Please try again.
Members
ServiceException
Description
The service encountered an error. Follow the instructions in the error message and try again.