Multiple AWS Cred in Java Spring

In my POC project, we would like to use S3 from one AWS user account (AWS api key set 1) and SQS from other AWS user account (AWS api key set 2)?

I checked article below:

As per this article we can build credential provider, but (as per my understanding) often credential provider is global value in java application… Can we use multiple key sets in single Spring boot application?

Leave a Reply

1 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
newest oldest most voted
Notify of

Credentials Providers in Spring are not global, but you can make them global by creating a Bean. Instead what you can potentially do is create two separate components: one for SQSClient another for S3Client, both configured using a different AWS Account and then autowire them as per need. import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.regions.Regions; import; import; import; import; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @Configuration public class AwsClientConfig { //AWS Account 1: region1/accessKey1/secretKey1 @Bean public AmazonSQS awsSQSClient(SqsConfig sqsConfig) { AmazonSQS sqs = AmazonSQSClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey1, secretKey1))) .withRegion(Regions.fromName(region1)) .build(); return sqs; } //AWS Account 2: region2/accessKey2/secretKey2… Read more »