sendSSHPublicKey method
Pushes an SSH public key to a particular OS user on a given EC2 instance for 60 seconds.
May throw AuthException. May throw InvalidArgsException. May throw ServiceException. May throw ThrottlingException. May throw EC2InstanceNotFoundException.
Parameter availabilityZone
:
The availability zone the EC2 instance was launched in.
Parameter instanceId
:
The EC2 instance you wish to publish the SSH key to.
Parameter instanceOSUser
:
The OS user on the EC2 instance whom the key may be used to authenticate
as.
Parameter sSHPublicKey
:
The public key to be published to the instance. To use it after
publication you must have the matching private key.
Implementation
Future<SendSSHPublicKeyResponse> sendSSHPublicKey({
required String availabilityZone,
required String instanceId,
required String instanceOSUser,
required String sSHPublicKey,
}) async {
ArgumentError.checkNotNull(availabilityZone, 'availabilityZone');
_s.validateStringLength(
'availabilityZone',
availabilityZone,
6,
32,
isRequired: true,
);
ArgumentError.checkNotNull(instanceId, 'instanceId');
_s.validateStringLength(
'instanceId',
instanceId,
10,
32,
isRequired: true,
);
ArgumentError.checkNotNull(instanceOSUser, 'instanceOSUser');
_s.validateStringLength(
'instanceOSUser',
instanceOSUser,
1,
32,
isRequired: true,
);
ArgumentError.checkNotNull(sSHPublicKey, 'sSHPublicKey');
_s.validateStringLength(
'sSHPublicKey',
sSHPublicKey,
256,
4096,
isRequired: true,
);
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: {
'AvailabilityZone': availabilityZone,
'InstanceId': instanceId,
'InstanceOSUser': instanceOSUser,
'SSHPublicKey': sSHPublicKey,
},
);
return SendSSHPublicKeyResponse.fromJson(jsonResponse.body);
}