【问题标题】:Using AWS (S3) via jclouds - how to assume role通过 jclouds 使用 AWS (S3) - 如何承担角色
【发布时间】:2014-06-24 13:45:09
【问题描述】:

当使用普通的身份验证凭据时,我可以这样做:

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

... 访问 S3 的 BlobStoreContext。

在本机 Amazon java api 中,我可以使用安全令牌服务 (STS) 担任角色并使用临时凭证来访问 S3 或任何其他 AWS 服务。

我如何在 jclouds 中做到这一点?

【问题讨论】:

    标签: java amazon-web-services amazon-s3 jclouds aws-sts


    【解决方案1】:

    我想通了。

    此代码 sn-p 允许承担角色并使用临时凭据访问 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);
    

    【讨论】:

      猜你喜欢
      • 2020-04-29
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-10
      • 2018-01-15
      相关资源
      最近更新 更多