Manual authentication for AWS EC2 API in jclouds, separating token acquisition

112 Views Asked by At

Some time ago I needed help for similar behavior for Google Compute Engine. But at the moment I need to do the same, getting the authorization token for the AWS API. This behavior is not yet implemented by the library explicitly.

The previous ask was: Manual authentication for Google API in jclouds

EDIT:

Actually, I'd like to get this session token in an earlier step somehow:

Token token = methodGetToken(<temp_access_key>, <temm_access_secret>);

SessionCredentials credentials = SessionCredentials.builder()
    .sessionToken( token.toString() )
    .build();

ContextBuilder.newBuilder("aws-ec2")
    .credentialsSupplier(Suppliers.ofInstance(credentials))
    ...
1

There are 1 best solutions below

0
Ignasi Barrera On

Do you mean authenticating to AWS using a session token you already have? If that is the case, you can build a SessionCredentials object and pass it to the jclouds ContextBuilder when creating the context. Something like:

SessionCredentials credentials = SessionCredentials.builder()
    .accessKeyId(<temp_access_key>)
    .secretAccessKey(<temm_access_secret>)
    .sessionToken(<session_token>)
    .build();

ContextBuilder.newBuilder("aws-ec2")
    .credentialsSupplier(Suppliers.ofInstance(credentials))
    ...