我有以下内容:
AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
final AWSCredentials credentials;
try {
credentials = credentialsProvider.getCredentials();
} catch (Exception e) {
LOGGER.error("AWS profile exception: {}", e);
throw new AmazonClientException(e.getMessage());
}
AmazonSQSClientBuilder sqsClientBuilder = AmazonSQSClientBuilder.standard();
sqsClientBuilder.setCredentials(new AWSStaticCredentialsProvider(credentials));
sqsClientBuilder.setRegion(config.getAwsRegion());
AmazonSQS sqsClient = sqsClientBuilder.build();
然而,过了一会儿,我得到com.amazonaws.services.sqs.model.AmazonSQSException: The security token included in the request is expired (Service: AmazonSQS; Status Code: 403; Error Code: ExpiredToken
如何设置我的客户端以便自动刷新客户端?
答案 0 :(得分:0)
不要手动设置凭据(.getCredentials()),如果提供者作为构造函数arg传递,aws sdk(1.10.x)将自动刷新令牌。
sqs=new AmazonSQSClient( new DefaultAWSCredentialsProviderChain());
与您的情况一样,您可以跳过设置凭据,因为AmazonSQSClientBuilder
默认情况下会根据doc从DefaultAWSCredentialProviderChain()
获取凭据