use of software.amazon.awssdk.services.ec2.model.DeleteKeyPairRequest in project cloudbreak by hortonworks.
the class AwsResourceConnector method deleteKeyPair.
private void deleteKeyPair(AuthenticatedContext ac, CloudStack stack) {
AwsCredentialView awsCredential = new AwsCredentialView(ac.getCloudCredential());
String region = ac.getCloudContext().getLocation().getRegion().value();
if (!awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) {
try {
AmazonEC2Client client = awsClient.createAccess(awsCredential, region);
DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(awsClient.getKeyPairName(ac));
client.deleteKeyPair(deleteKeyPairRequest);
} catch (Exception e) {
String errorMessage = String.format("Failed to delete public key [roleArn:'%s', region: '%s'], detailed message: %s", awsCredential.getRoleArn(), region, e.getMessage());
LOGGER.error(errorMessage, e);
}
}
}
use of software.amazon.awssdk.services.ec2.model.DeleteKeyPairRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteKeyPair method deleteKeys.
// snippet-start:[ec2.java2.delete_key_pair.main]
public static void deleteKeys(Ec2Client ec2, String keyPair) {
try {
DeleteKeyPairRequest request = DeleteKeyPairRequest.builder().keyName(keyPair).build();
DeleteKeyPairResponse response = ec2.deleteKeyPair(request);
System.out.printf("Successfully deleted key pair named %s", keyPair);
} catch (Ec2Exception e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.ec2.model.DeleteKeyPairRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteKeyPair method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a key pair name\n" + "Ex: DeleteKeyPair <key-pair-name>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String key_name = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DeleteKeyPairRequest request = new DeleteKeyPairRequest().withKeyName(key_name);
DeleteKeyPairResult response = ec2.deleteKeyPair(request);
System.out.printf("Successfully deleted key pair named %s", key_name);
}
Aggregations