You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jclouds.apache.org by David Bosschaert <da...@gmail.com> on 2014/08/28 18:24:39 UTC
Specifying EC2 keypair?
Hi all,
I'm creating nodes on EC2 with ComputeService.createNodesInGroup() and
would like to use a keypair provided by Amazon as a .pem file to
access it later.
I thought that I could do this by passing the content of the .pem file
into the EC2TemplateOptions like this:
EC2TemplateOptions opts = EC2TemplateOptions.Builder
.keyPair(keyPairString)
However, that gives me the following error message:
"please use options.overrideLoginCredentialWith(rsa_private_text)
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:120)"
However that overrideLoginCredentialWith() method doesn't exist on the
EC2TemplateOptions.
Is there a way to use the key that I received as .pem file for nodes
that I create with ComputeService.createNodesInGroup()?
Thanks,
David
Re: Specifying EC2 keypair?
Posted by Andrew Phillips <an...@apache.org>.
> After some more experimenting I found out how it works.
Thanks for the details, David - glad to hear it's working!
ap
Re: Specifying EC2 keypair?
Posted by Ignasi Barrera <na...@apache.org>.
Hi!
I'm a bit late, but you should be able to just do:
TemplateOptions options = compute.templateOptions()
.authorizePublicKey("pubkey string")
.inboundPorts(inboundPorts)
.runScript(bootInstructions);
Without using EC2 specific options (more portable code) or all those
credential overrides. That should be enough, as the "authorizePublicKey"
should take care of creating a key pair for you.
I.
On 29 August 2014 00:10, Andrew Phillips <an...@apache.org> wrote:
>> However that overrideLoginCredentialWith() method doesn't exist on the
>> EC2TemplateOptions.
>
>
> Which version of jclouds are you using, David? According to the Javadocs
> [1], EC2TemplateOptions should have a number of "overrideLogin*" methods.
>
> But you're right, there seems to be a typo there: I suspect the intended
> method is either "overrideLoginCredentials" or "overrideLoginPrivateKey".
>
> Hope that helps!
Thanks Andrew,
After some more experimenting I found out how it works. The
EC2TemplateOptions.keyPair() method takes the name of the key under
which you registered it with AWS. So it could be something as simple
as "davids_key" or something. I mistakenly thought that you had to
pass the actual public key content through that method.
To create instances that I can then later log into using my key, I'm
currently doing the following:
AdminAccess bootInstructions =
AdminAccess.builder().adminUsername("ec2-user").
adminPublicKey(myPublicKeyContent).build();
EC2TemplateOptions opts = EC2TemplateOptions.Builder
.overrideLoginCredentials(
LoginCredentials.builder().user("ec2-user").privateKey(myPrivateKeyContent).build())
.keyPair("davids_key") // the name I gave my key when I uploaded it to
AWS
.inboundPorts(inboundPorts)
.runScript(bootInstructions);
TemplateBuilder templateBuilder = compute.templateBuilder();
templateBuilder
.hardwareId(instanceType)
.imageId(imageID)
.options(opts);
compute.createNodesInGroup("myGroupName", 1, templateBuilder.build());
This is working fine for me. I can also log into the instances created using
ssh -i <myprivatekey> ec2-user@1.2.3.4
If someone spots anything wrong with it, let me know :)
Cheers,
David
BTW I'm currently using JCouds 1.7.3
Re: Specifying EC2 keypair?
Posted by David Bosschaert <da...@gmail.com>.
On 29 August 2014 00:10, Andrew Phillips <an...@apache.org> wrote:
>> However that overrideLoginCredentialWith() method doesn't exist on the
>> EC2TemplateOptions.
>
>
> Which version of jclouds are you using, David? According to the Javadocs
> [1], EC2TemplateOptions should have a number of "overrideLogin*" methods.
>
> But you're right, there seems to be a typo there: I suspect the intended
> method is either "overrideLoginCredentials" or "overrideLoginPrivateKey".
>
> Hope that helps!
Thanks Andrew,
After some more experimenting I found out how it works. The
EC2TemplateOptions.keyPair() method takes the name of the key under
which you registered it with AWS. So it could be something as simple
as "davids_key" or something. I mistakenly thought that you had to
pass the actual public key content through that method.
To create instances that I can then later log into using my key, I'm
currently doing the following:
AdminAccess bootInstructions =
AdminAccess.builder().adminUsername("ec2-user").
adminPublicKey(myPublicKeyContent).build();
EC2TemplateOptions opts = EC2TemplateOptions.Builder
.overrideLoginCredentials(
LoginCredentials.builder().user("ec2-user").privateKey(myPrivateKeyContent).build())
.keyPair("davids_key") // the name I gave my key when I uploaded it to AWS
.inboundPorts(inboundPorts)
.runScript(bootInstructions);
TemplateBuilder templateBuilder = compute.templateBuilder();
templateBuilder
.hardwareId(instanceType)
.imageId(imageID)
.options(opts);
compute.createNodesInGroup("myGroupName", 1, templateBuilder.build());
This is working fine for me. I can also log into the instances created using
ssh -i <myprivatekey> ec2-user@1.2.3.4
If someone spots anything wrong with it, let me know :)
Cheers,
David
BTW I'm currently using JCouds 1.7.3
Re: Specifying EC2 keypair?
Posted by Andrew Phillips <an...@apache.org>.
> However that overrideLoginCredentialWith() method doesn't exist on the
> EC2TemplateOptions.
Which version of jclouds are you using, David? According to the
Javadocs [1], EC2TemplateOptions should have a number of
"overrideLogin*" methods.
But you're right, there seems to be a typo there: I suspect the
intended method is either "overrideLoginCredentials" or
"overrideLoginPrivateKey".
Hope that helps!
ap
[1]
http://javadocs.jclouds.cloudbees.net/org/jclouds/ec2/compute/options/EC2TemplateOptions.html