当前位置: 首页>>代码示例>>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;未经允许,请勿转载。