Search in sources :

Example 6 with CreateKeyPairRequest

use of software.amazon.awssdk.services.ec2.model.CreateKeyPairRequest in project incubator-gobblin by apache.

the class AWSSdkClient method createKeyValuePair.

/**
 * Creates a 2048-bit RSA key pair with the specified name
 *
 * @param keyName Key name to use
 * @return Unencrypted PEM encoded PKCS#8 private key
 */
public String createKeyValuePair(String keyName) {
    final AmazonEC2 amazonEC2 = getEc2Client();
    final CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName);
    final CreateKeyPairResult createKeyPairResult = amazonEC2.createKeyPair(createKeyPairRequest);
    final KeyPair keyPair = createKeyPairResult.getKeyPair();
    final String material = keyPair.getKeyMaterial();
    LOGGER.info("Created key: " + keyName);
    LOGGER.debug("Created material: " + material);
    return material;
}
Also used : KeyPair(com.amazonaws.services.ec2.model.KeyPair) CreateKeyPairResult(com.amazonaws.services.ec2.model.CreateKeyPairResult) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) CreateKeyPairRequest(com.amazonaws.services.ec2.model.CreateKeyPairRequest)

Aggregations

CreateKeyPairRequest (com.amazonaws.services.ec2.model.CreateKeyPairRequest)5 CreateKeyPairResult (com.amazonaws.services.ec2.model.CreateKeyPairResult)5 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)3 KeyPair (com.amazonaws.services.ec2.model.KeyPair)2 File (java.io.File)2 IOException (java.io.IOException)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 AuthorizeSecurityGroupIngressRequest (com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest)1 CreateSecurityGroupRequest (com.amazonaws.services.ec2.model.CreateSecurityGroupRequest)1 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)1 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)1 DescribeKeyPairsRequest (com.amazonaws.services.ec2.model.DescribeKeyPairsRequest)1 DescribeKeyPairsResult (com.amazonaws.services.ec2.model.DescribeKeyPairsResult)1 IpPermission (com.amazonaws.services.ec2.model.IpPermission)1 IpRange (com.amazonaws.services.ec2.model.IpRange)1 KeyPairInfo (com.amazonaws.services.ec2.model.KeyPairInfo)1 MonitorInstancesRequest (com.amazonaws.services.ec2.model.MonitorInstancesRequest)1 RebootInstancesRequest (com.amazonaws.services.ec2.model.RebootInstancesRequest)1 RunInstancesRequest (com.amazonaws.services.ec2.model.RunInstancesRequest)1 StartInstancesRequest (com.amazonaws.services.ec2.model.StartInstancesRequest)1