sendSSHPublicKey method

Future<SendSSHPublicKeyResponse> sendSSHPublicKey({
  1. required String instanceId,
  2. required String instanceOSUser,
  3. required String sSHPublicKey,
  4. String? availabilityZone,
})

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.

May throw AuthException. May throw EC2InstanceNotFoundException. May throw EC2InstanceStateInvalidException. May throw EC2InstanceUnavailableException. May throw InvalidArgsException. May throw ServiceException. May throw ThrottlingException.

Parameter instanceId : The ID of the EC2 instance.

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

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

Parameter availabilityZone : The Availability Zone in which the EC2 instance was launched.

Implementation

Future<SendSSHPublicKeyResponse> sendSSHPublicKey({
  required String instanceId,
  required String instanceOSUser,
  required String sSHPublicKey,
  String? availabilityZone,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSEC2InstanceConnectService.SendSSHPublicKey'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'InstanceId': instanceId,
      'InstanceOSUser': instanceOSUser,
      'SSHPublicKey': sSHPublicKey,
      if (availabilityZone != null) 'AvailabilityZone': availabilityZone,
    },
  );

  return SendSSHPublicKeyResponse.fromJson(jsonResponse.body);
}