當前位置: 首頁>>代碼示例>>Java>>正文


Java AmazonEC2.createKeyPair方法代碼示例

本文整理匯總了Java中com.amazonaws.services.ec2.AmazonEC2.createKeyPair方法的典型用法代碼示例。如果您正苦於以下問題:Java AmazonEC2.createKeyPair方法的具體用法?Java AmazonEC2.createKeyPair怎麽用?Java AmazonEC2.createKeyPair使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.amazonaws.services.ec2.AmazonEC2的用法示例。


在下文中一共展示了AmazonEC2.createKeyPair方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
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);
}
 
開發者ID:awsdocs,項目名稱:aws-doc-sdk-examples,代碼行數:25,代碼來源:CreateKeyPair.java

示例2: createKeyValuePair

import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
/***
 * 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;
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:20,代碼來源:AWSSdkClient.java

示例3: submitEC2Key

import com.amazonaws.services.ec2.AmazonEC2; //導入方法依賴的package包/類
@Action(value = "/manage/submitEC2Key",
        results = {
                @Result(name = "input", location = "/manage/view_ec2_keys.jsp"),
                @Result(name = "success", location = "/manage/viewEC2Keys.action", type = "redirect")
        }
)
public String submitEC2Key() {

    String retVal = SUCCESS;

    try {

        //get AWS credentials from DB
        AWSCred awsCred = AWSCredDB.getAWSCred(ec2Key.getAwsCredId());

        //set  AWS credentials for service
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsCred.getAccessKey(), awsCred.getSecretKey());

        //create service
        AmazonEC2 service = AmazonEC2ClientBuilder.standard()
                .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
                .withClientConfiguration(AWSClientConfig.getClientConfig())
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(ec2Key.getEc2Region(), ec2RegionMap.get(ec2Key.getEc2Region()))).build();

        //create key pair request
        CreateKeyPairRequest createKeyPairRequest = new CreateKeyPairRequest();
        createKeyPairRequest.withKeyName(ec2Key.getKeyNm());

        //call service
        CreateKeyPairResult createKeyPairResult = service.createKeyPair(createKeyPairRequest);
        //get key pair result
        KeyPair keyPair = createKeyPairResult.getKeyPair();

        //set private key
        String privateKey = keyPair.getKeyMaterial();
        ec2Key.setPrivateKey(privateKey);

        //add to db
        EC2KeyDB.saveEC2Key(ec2Key);

    } catch (AmazonServiceException ex) {
        addActionError(ex.getMessage());
        retVal = INPUT;
    }

    return retVal;

}
 
開發者ID:skavanagh,項目名稱:EC2Box,代碼行數:49,代碼來源:EC2KeyAction.java


注:本文中的com.amazonaws.services.ec2.AmazonEC2.createKeyPair方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。