Kousha
Kousha

Reputation: 36279

SQSClient token expires; need auto refresh

I have the following:

    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();

However, after a while, I get com.amazonaws.services.sqs.model.AmazonSQSException: The security token included in the request is expired (Service: AmazonSQS; Status Code: 403; Error Code: ExpiredToken

How can I setup my client so it automatically refreshes the client?

Upvotes: 0

Views: 2025

Answers (1)

Ravi
Ravi

Reputation: 982

Don't set the credentials manually (.getCredentials()), aws sdk (1.10.x) will automatically refresh tokens if provider is passed as constructor arg.

sqs=new AmazonSQSClient( new DefaultAWSCredentialsProviderChain());

As in your case, You may skip setting credentials as AmazonSQSClientBuilder by default gets credentials from DefaultAWSCredentialProviderChain() as per doc

Upvotes: 1

Related Questions