Using AWS (S3) via jclouds - how to assume role

不羁的心 提交于 2019-12-12 20:38:24

问题


When using plain auth credentials I can do:

ContextBuilder.newBuilder("aws-s3").credentials(keyId, key).buildView(BlobStoreContext.class);

... to access BlobStoreContext for S3.

In native Amazon java api I can use Security Token Service (STS) to assume role and use temporary credentials to access S3 or any other AWS service.

How do I do this in jclouds?


回答1:


I figured it out.

This code snippet allows to assume role and use temp credentials to access S3:

STSApi api = ContextBuilder.newBuilder("sts").credentials(keyId,
        key).buildApi(STSApi.class);

AssumeRoleOptions assumeRoleOptions = new AssumeRoleOptions().durationSeconds(3600).externalId(externalId);
final UserAndSessionCredentials credentials = api.assumeRole(roleArn, sessionName, assumeRoleOptions);

Supplier<Credentials> credentialsSupplier = new Supplier<Credentials>() {
    @Override
    public Credentials get() {
        return credentials.getCredentials();
    }
};
BlobStoreContext context = ContextBuilder.newBuilder("aws-s3").credentialsSupplier(credentialsSupplier).buildView(BlobStoreContext.class);


来源:https://stackoverflow.com/questions/23520216/using-aws-s3-via-jclouds-how-to-assume-role

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!