public static void main(String[] args) { final String USAGE = "To run this example, supply a key pair name\n" + "Ex: CreateKeyPair <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(); CreateKeyPairRequest request = new CreateKeyPairRequest() .withKeyName(key_name); CreateKeyPairResult response = ec2.createKeyPair(request); System.out.printf( "Successfulyl created key pair named %s", key_name); }
private void createKeyPair() throws IOException, FileNotFoundException { DescribeKeyPairsResult response = ec2.describeKeyPairs(); boolean check_key=false; for(KeyPairInfo key_pair : response.getKeyPairs()) { if(key_pair.getKeyName().equalsIgnoreCase(MY_KEY)) { check_key=true; break; } } if(!check_key) { File file=new File(System.getProperty("user.home")+"/.aws/"+MY_KEY+".pem"); if(!file.exists()) file.createNewFile(); else{ System.err.println("Connot create the key pair to access to the cluster!"); System.exit(1); } System.out.println("Create new key pair ~/.aws/"+MY_KEY+".pem"); CreateKeyPairRequest request = new CreateKeyPairRequest() .withKeyName(MY_KEY); CreateKeyPairResult responsetocreate = ec2.createKeyPair(request); PrintWriter print = new PrintWriter(file); print.print(responsetocreate.getKeyPair().getKeyMaterial()); print.close(); Runtime.getRuntime().exec("chmod 0400 "+System.getProperty("user.home")+"/.aws/"+MY_KEY+".pem"); } }
@Override public String create(Instance instance) { CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest(); createKeyPairRequest.withKeyName(instance.getKeyName()); CreateKeyPairResult createKeyPairResult = ec2UserClient.amazonEC2Async().createKeyPair(createKeyPairRequest); KeyPair keyPair = createKeyPairResult.getKeyPair(); return keyPair.getKeyMaterial(); }
/*** * 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; }
@Override public KeyPair createKeyPair(CreateKeyPairRequest request, ResultCapture<CreateKeyPairResult> extractor) { ActionResult result = service.performAction("CreateKeyPair", request, extractor); if (result == null) return null; return new KeyPairImpl(result.getResource()); }
@Override public KeyPair createKeyPair(String keyName, ResultCapture<CreateKeyPairResult> extractor) { CreateKeyPairRequest request = new CreateKeyPairRequest() .withKeyName(keyName); return createKeyPair(request, extractor); }
@Override public CreateKeyPairResult createKeyPair(CreateKeyPairRequest createKeyPairRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
public KeyPair createKeyPair(String keyName) { logger.info("create key pair, keyName={}", keyName); CreateKeyPairResult result = ec2.createKeyPair(new CreateKeyPairRequest().withKeyName(keyName)); return result.getKeyPair(); }
public CreateKeyPairResult createKeyPair(AmazonEC2Client client, String keyName) { CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest().withKeyName(keyName); CreateKeyPairResult createKeyPairResult = client.createKeyPair(createKeyPairRequest); return createKeyPairResult; }
@Override public CreateKeyPairResult createKeyPair(AWSCredentials credentials, String keyName) { return createKeyPair(amazonEC2ClientFactory.createAmazonEC2Client(credentials), keyName); }
@RequestMapping(method = RequestMethod.GET, value = {"/keypairs/create"}) @ResponseBody public CreateKeyPairResult createKeyPairs(@RequestParam("name") String name, @RequestParam("accessKey") String accessKey, @RequestParam("secretKey") String secretKey) { return awsec2Service.createKeyPair(awsCredentialsFactory.createSimpleAWSCredentials(accessKey, secretKey), name); }
@Override public KeyPair createKeyPair(String keyName) { return createKeyPair(keyName, (ResultCapture<CreateKeyPairResult>)null); }
/** * Performs the <code>CreateKeyPair</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * * @return The <code>KeyPair</code> resource object associated with the * result of this action. * @see CreateKeyPairRequest */ com.amazonaws.resources.ec2.KeyPair createKeyPair(CreateKeyPairRequest request, ResultCapture<CreateKeyPairResult> extractor);
/** * The convenient method form for the <code>CreateKeyPair</code> action. * * @see #createKeyPair(CreateKeyPairRequest, ResultCapture) */ com.amazonaws.resources.ec2.KeyPair createKeyPair(String keyName, ResultCapture<CreateKeyPairResult> extractor);
CreateKeyPairResult createKeyPair(AWSCredentials credentials, String keyName);