繁体   English   中英

AssumeRoleResult 不返回任何内容

[英]AssumeRoleResult not returning anything

我正在尝试获取临时安全凭证并使用它们在 Kinesis stream 上推送/发布数据。 请检查以下代码以获取凭据。

private AssumeRoleResult getAssumeRoleResult() {
    AssumeRoleResult assumeRoleResult = null;
    try {
        log.info("Started to fetch AssumeRoleResult");
        BasicSessionCredentials currentRoleCredentials = getCredentialsOfCurrentRole();
        String sessionName = "assumedRole_" + RandomStringUtils.randomAlphanumeric(5).toUpperCase();
        region = Config.getRegion();
        AWSSecurityTokenService sts = AWSSecurityTokenServiceClientBuilder.standard()
                                .withCredentials(new AWSStaticCredentialsProvider(currentRoleCredentials)).withRegion(region)
                                .build();
        String roleArn = Configurations.ROLE_ARN;
        assumeRoleResult = sts.assumeRole(new AssumeRoleRequest().withRoleArn(roleArn)
                                        .withDurationSeconds(AWS_KINESIS_SESSION_DURATION)
                                        .withRoleSessionName(sessionName));
        log.info("Your AssumeRoleResult is" + assumeRoleResult.toString())
        return assumeRoleResult;
    } catch(Exception e) {
        log.error("Failed to get AssumeRoleResult with error : {}", e.getMessage());
        e.printStackTrace();
    }
}


private BasicSessionCredentials getCredentialsOfCurrentRole() throws JSONException {
    // Code to fetch IAM credentials for current role
}

但是当我检查日志时,发现assumeRoleResult没有返回任何东西。(我没有看到任何日志说“你的AssumeRoleResult 是”,也没有发现异常)。

你能告诉我这里可能有什么问题吗?

为了解决这个问题,我添加了以下更改

  1. 更新了给定账户https://aws.amazon.com/blogs/security/how-to-use-trust-policies-with-iam-roles/信任关系

  2. 将 aws-java-sdk-kinesisaws-java-sdk-sts更新到最新版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM