Example usage for com.amazonaws.services.ec2.model ImportKeyPairResult getKeyName

List of usage examples for com.amazonaws.services.ec2.model ImportKeyPairResult getKeyName

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model ImportKeyPairResult getKeyName.

Prototype


public String getKeyName() 

Source Link

Document

The key pair name you provided.

Usage

From source file:com.nike.cerberus.service.Ec2Service.java

License:Apache License

/**
 * Import a key pair to AWS EC2.// w  w w. ja v a 2 s  .  c  o m
 *
 * @param keyName Friendly name for the key
 * @param publicKeyMaterial Public key
 * @return Key name
 */
public String importKey(final String keyName, final String publicKeyMaterial) {
    final ImportKeyPairRequest request = new ImportKeyPairRequest(keyName, publicKeyMaterial);
    final ImportKeyPairResult result = ec2Client.importKeyPair(request);
    return result.getKeyName();
}

From source file:org.occiware.clouddriver.IAM.KeyPairOperation.java

License:Apache License

/**
 * Import key pair to AWS.//from  ww w.  j  ava  2s  .c  om
 * @param keyPair a keypair data object with a public key and a name set..
 * @throws KeyPairOperationException Exception when aws exception when importing a new key pair.
 */
public void importKeyPair(KeyPairDO keyPair) throws KeyPairOperationException {

    String keyPairName = keyPair.getKeyPairName();
    String encodedPublicKey = keyPair.getPublicKey(); // Base 64 encoded, DER

    if (keyPairName == null) {
        throw new KeyPairOperationException("The keyPair name must be provided for operation import KeyPair.");
    }
    if (encodedPublicKey == null) {
        throw new KeyPairOperationException(
                "The keyPair public key encoded base 64, DER must be provided for operation importKeyPair.");
    }
    try {
        ImportKeyPairResult result = ec2Client.getClientInstance()
                .importKeyPair(new ImportKeyPairRequest(keyPairName, encodedPublicKey));
        keyPair.setKeyPairName(result.getKeyName());
        keyPair.setFingerPrintPublicKey(result.getKeyFingerprint());
        ec2Client.getClientInstance().shutdown();
    } catch (AmazonServiceException ase) {
        logger.error("Exception thrown from aws : " + ase.getErrorCode() + " --> " + ase.getErrorMessage());
        throw new KeyPairOperationException(ase);
    } catch (AmazonClientException ace) {
        logger.error("Exception thrown from aws : " + ace.getMessage());
        throw new KeyPairOperationException(ace);
    } finally {
        ec2Client.getClientInstance().shutdown();
    }
}