Я пытаюсь подключиться к AWS sqs после принятия правила, и я получаю просроченные ошибки маркера безопасности через час, как я могу автоматически обновить соединение?
@Bean
public QueueMessagingTemplate queueMessagingTemplate(){
return new QueueMessagingTemplate(amazonSQSAsync());
}
private AmazonSQSAsync amazonSQSAsync(){
try {
logger.info("Start amazonSQSAsync");
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
.withCredentials(new DefaultAWSCredentialsProviderChain())
.withRegion(AWS_REGION)
.build();
logger.info("stsClient created successfully");
AssumeRoleRequest roleRequest = new AssumeRoleRequest()
.withRoleArn(ROLE_ARN)
.withRoleSessionName(ROLE_SESSION_NAME)
.withDurationSeconds(3600);
AssumeRoleResult assumeRoleResult = stsClient.assumeRole(roleRequest);
logger.info("assumeRoleResult created successfully");
BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
assumeRoleResult.getCredentials().getAccessKeyId(),
assumeRoleResult.getCredentials().getSecretAccessKey(),
assumeRoleResult.getCredentials().getSessionToken());
logger.info("basicSessionCredentials created successfully");
AmazonSQSAsync amazonSQSAsync = AmazonSQSAsyncClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(basicSessionCredentials))
.withRegion(AWS_REGION).build();
// .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(SQS_URL,"us-east-2"))
logger.info("amazonSQSAsync created successfully");
return amazonSQSAsync;
} catch (Exception e){
logger.error("Failed to create Amazon sqs client", e);
throw e;
}
}