deleteKeyPair method

Future<DeleteKeyPairResult> deleteKeyPair({
  1. required String keyPairName,
  2. String? expectedFingerprint,
})

Deletes the specified key pair by removing the public key from Amazon Lightsail.

You can delete key pairs that were created using the ImportKeyPair and CreateKeyPair actions, as well as the Lightsail default key pair. A new default key pair will not be created unless you launch an instance without specifying a custom key pair, or you call the DownloadDefaultKeyPair API.

The delete key pair operation supports tag-based access control via resource tags applied to the resource identified by key pair name. For more information, see the Amazon Lightsail Developer Guide.

May throw AccessDeniedException. May throw AccountSetupInProgressException. May throw InvalidInputException. May throw NotFoundException. May throw OperationFailureException. May throw RegionSetupInProgressException. May throw ServiceException. May throw UnauthenticatedException.

Parameter keyPairName : The name of the key pair to delete.

Parameter expectedFingerprint : The RSA fingerprint of the Lightsail default key pair to delete.

Implementation

Future<DeleteKeyPairResult> deleteKeyPair({
  required String keyPairName,
  String? expectedFingerprint,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'Lightsail_20161128.DeleteKeyPair'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'keyPairName': keyPairName,
      if (expectedFingerprint != null)
        'expectedFingerprint': expectedFingerprint,
    },
  );

  return DeleteKeyPairResult.fromJson(jsonResponse.body);
}