On 29 August 2014 00:10, Andrew Phillips <andr...@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

Reply via email to