Skip to content

Commit ace2fe6

Browse files
feat: adding support for session credentials
1 parent 84ccc36 commit ace2fe6

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/main/java/br/com/grupo63/serviceproduction/config/DynamoDBConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public AmazonDynamoDB amazonDynamoDB(AWSCredentials awsCredentials) {
4444
}
4545

4646
@Bean
47-
public AWSCredentials awsCredentials() {
47+
public AWSCredentials AWSCredentials() {
4848
if (awsSessionToken == null || awsSessionToken.isBlank()) {
4949
return new BasicAWSCredentials(
5050
awsAccessKey, awsSecretKey);

src/main/java/br/com/grupo63/serviceproduction/config/SQSClientConfig.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import org.springframework.context.annotation.Bean;
55
import org.springframework.context.annotation.Configuration;
66
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
7+
import software.amazon.awssdk.auth.credentials.AwsCredentials;
8+
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
79
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
810
import software.amazon.awssdk.regions.Region;
911
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
@@ -17,16 +19,27 @@ class SQSClientConfig {
1719
@Value("${spring.cloud.aws.credentials.secret-key}")
1820
private String secretKey;
1921

22+
@Value("${app.aws.session-token}")
23+
private String sessionToken;
24+
2025
@Value("${spring.cloud.aws.region.static}")
2126
private String region;
2227

2328
@Bean
24-
SqsAsyncClient sqsAsyncClient(){
29+
SqsAsyncClient sqsAsyncClient(AwsCredentials awsCredentials) {
2530
return SqsAsyncClient
2631
.builder()
2732
.region(Region.of(region))
2833
.credentialsProvider(StaticCredentialsProvider
29-
.create(AwsBasicCredentials.create(accessKey, secretKey)))
34+
.create(awsCredentials))
3035
.build();
3136
}
37+
38+
@Bean
39+
public AwsCredentials awsCredentials() {
40+
if (sessionToken == null || sessionToken.isBlank()) {
41+
return AwsBasicCredentials.create(accessKey, secretKey);
42+
}
43+
return AwsSessionCredentials.create(accessKey, secretKey, sessionToken);
44+
}
3245
}

src/main/resources/application-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spring:
1919
access-key: "${AWS_ACCESS_KEY:accesskey}"
2020
secret-key: "${AWS_SECRET_KEY:secretkey}"
2121
region:
22-
static: "us-east-2"
22+
static: "${AWS_REGION:us-east-2}"
2323
sqs:
2424
endpoint: "${AWS_SQS_ENDPOINT:endpoint}"
2525
jwt:

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spring:
2020
access-key: "${AWS_ACCESS_KEY:accesskey}"
2121
secret-key: "${AWS_SECRET_KEY:secretkey}"
2222
region:
23-
static: "us-east-2"
23+
static: "${AWS_REGION:us-east-2}"
2424
sqs:
2525
endpoint: "${AWS_SQS_ENDPOINT:endpoint}"
2626

0 commit comments

Comments
 (0)