简体   繁体   English

在访问密钥的帮助下,使用jclouds创建和下载AWS ec2密钥对

[英]Create and download an AWS ec2 keypair using jclouds with the help of access, secret key

I am able to create AWS-EC2 instance using jClouds API with the help of access key and secret key, 我可以使用jClouds API在访问密钥和密钥的帮助下创建AWS-EC2实例,

AWS_ACCESS_KEY = this.config.getString("aws_access_key");
AWS_SECRET_ACCESS_KEY = this.config.getString("aws_secret_access_key");

if (AWS_ACCESS_KEY == null || AWS_SECRET_ACCESS_KEY == null) {
    throw new InstantiationError("Invalid AWS Credentails");
}

ec2Api = ContextBuilder.newBuilder(AWS_EC2).credentials(AWS_ACCESS_KEY, AWS_SECRET_ACCESS_KEY).buildApi(EC2Api.class);
instanceApi = ec2Api.getInstanceApi().get();

How to create a Key pair on AWS-EC2 when user is creating an instance for first time (jCloud API). 当用户第一次创建实例(jCloud API)时,如何在AWS-EC2上创建密钥对。 Do we need to use existing access key and secret key for every new instance. 我们是否需要为每个新实例使用现有的访问密钥和密钥。

Can anyone please help me in advising how to create a new keypair for every new instance. 任何人都可以帮助我建议如何为每个新实例创建一个新的密钥对。

Template template = compute.templateBuilder()
            .hardwareId(InstanceType.T1_MICRO)
            .imageId("us-east-1/ami-ccf615a5")
            .osFamily(OsFamily.AMZN_LINUX)
            .locationId("us-east-1")
            .osVersionMatches("12.10")
            .build();
    Template template = templateBuilder.build();

    TemplateOptions templateOptions = template.getOptions();
    AWSEC2TemplateOptions awsTemplateOption= templateOptions.as(AWSEC2TemplateOptions.class);
    awsTemplateOption.securityGroups("securityGroupName");
    awsTemplateOption.keyPair("keyPairName");

try {
        Set<? extends NodeMetadata> nodes = compute.createNodesInGroup(groupName,1,template);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM