假设角色结果未返回任何内容

3

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

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没有返回任何内容。(我没有看到任何日志显示“Your AssumeRoleResult is”,也没有发现任何异常)。

请问可能出了什么问题?


1
这个函数开始时的信息消息是否出现在日志中?函数是返回还是一直挂起?如果两个问题的答案都是肯定的,那么我会考虑网络问题(例如,在没有NAT的私有子网上运行)。 - Parsifal
1
你对第二个问题的答案是“否”,请尝试将catch表达式替换为Throwable。我怀疑你可能会遇到NoClassDefFoundError,这不是Exception的子类。 - Parsifal
1个回答

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接