我正在尝试使用AWS Assume Role在线程内承担角色。但是,它给出的错误与承担角色流无关。
下面是run()
函数的代码
@Override
public void run() {
Session session = null;
try {
session = sessionFactory.openSession();
RmlWorkspace rmlWorkspace = session.get(RmlWorkspace.class, id);
logger.info("Starting Status check for "+id);
if (rmlWorkspace.getCloudStack().getStatus() == RUNNING_STATUS.STARTING) {
while (rmlWorkspace.getCloudStack().getStatus() != RUNNING_STATUS.ON) {
logger.info("Checking Status for "+id);
rmlWorkspace = checkStatus(session, rmlWorkspace);
TimeUnit.SECONDS.sleep(5);
}
} else if (rmlWorkspace.getCloudStack().getStatus() == RUNNING_STATUS.STOPPING) {
while (rmlWorkspace.getCloudStack().getStatus() != RUNNING_STATUS.OFF) {
rmlWorkspace = checkStatus(session, rmlWorkspace);
TimeUnit.SECONDS.sleep(5);
}
}
session.close();
} catch (Exception e) {
logger.info(e.getMessage());
if (session != null)
session.close();
}
}
假设角色功能如下:
private AssumeRoleResult assumeRole() {
try {
BasicAWSCredentials credentials = new BasicAWSCredentials(configAttributeService.getAttribute("aws.iamkey"),
configAttributeService.getAttribute("aws.iampass"));
AWSSecurityTokenService client = AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(Regions.US_WEST_2).withCredentials(new AWSStaticCredentialsProvider(credentials))
.build();
AssumeRoleRequest request = new AssumeRoleRequest()
.withRoleArn(configAttributeService.getAttribute("aws.assumerole"))
.withRoleSessionName(UUID.randomUUID().toString()).withDurationSeconds(900);
AssumeRoleResult assumeRoleResult = client.assumeRole(request);
return assumeRoleResult;
} catch (Exception e) {
throw e;
}
}
异常e显示了我上面提到的错误。有谁知道为什么会发生这种情况?
我正在将Spring Boot与Hibernate事务管理器一起使用。