Commit 3d9f1cf1e36223e3585fa9275b5cc66ec8f69192
Committed by
Andrew Shvayka
1 parent
45e3c229
enable default credential provider chain for aws sqs
Showing
3 changed files
with
17 additions
and
5 deletions
@@ -612,6 +612,10 @@ queue: | @@ -612,6 +612,10 @@ queue: | ||
612 | notifications: "${TB_QUEUE_KAFKA_NOTIFICATIONS_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000}" | 612 | notifications: "${TB_QUEUE_KAFKA_NOTIFICATIONS_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:1048576000}" |
613 | js-executor: "${TB_QUEUE_KAFKA_JE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:104857600}" | 613 | js-executor: "${TB_QUEUE_KAFKA_JE_TOPIC_PROPERTIES:retention.ms:604800000;segment.bytes:26214400;retention.bytes:104857600}" |
614 | aws_sqs: | 614 | aws_sqs: |
615 | + # @see https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-roles.html | ||
616 | + # setting this to true, will ignore the access keys below and instead use the | ||
617 | + # default credential provider chain, which includes instance profile credentials etc. | ||
618 | + use_default_credential_provider_chain: "${TB_QUEUE_AWS_SQS_USE_DEFAULT_CREDENTIAL_PROVIDER_CHAIN:false}" | ||
615 | access_key_id: "${TB_QUEUE_AWS_SQS_ACCESS_KEY_ID:YOUR_KEY}" | 619 | access_key_id: "${TB_QUEUE_AWS_SQS_ACCESS_KEY_ID:YOUR_KEY}" |
616 | secret_access_key: "${TB_QUEUE_AWS_SQS_SECRET_ACCESS_KEY:YOUR_SECRET}" | 620 | secret_access_key: "${TB_QUEUE_AWS_SQS_SECRET_ACCESS_KEY:YOUR_SECRET}" |
617 | region: "${TB_QUEUE_AWS_SQS_REGION:YOUR_REGION}" | 621 | region: "${TB_QUEUE_AWS_SQS_REGION:YOUR_REGION}" |
@@ -15,9 +15,7 @@ | @@ -15,9 +15,7 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.queue.sqs; | 16 | package org.thingsboard.server.queue.sqs; |
17 | 17 | ||
18 | -import com.amazonaws.auth.AWSCredentials; | ||
19 | -import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
20 | -import com.amazonaws.auth.BasicAWSCredentials; | 18 | +import com.amazonaws.auth.*; |
21 | import com.amazonaws.services.sqs.AmazonSQS; | 19 | import com.amazonaws.services.sqs.AmazonSQS; |
22 | import com.amazonaws.services.sqs.AmazonSQSClientBuilder; | 20 | import com.amazonaws.services.sqs.AmazonSQSClientBuilder; |
23 | import com.amazonaws.services.sqs.model.CreateQueueRequest; | 21 | import com.amazonaws.services.sqs.model.CreateQueueRequest; |
@@ -37,9 +35,16 @@ public class TbAwsSqsAdmin implements TbQueueAdmin { | @@ -37,9 +35,16 @@ public class TbAwsSqsAdmin implements TbQueueAdmin { | ||
37 | public TbAwsSqsAdmin(TbAwsSqsSettings sqsSettings, Map<String, String> attributes) { | 35 | public TbAwsSqsAdmin(TbAwsSqsSettings sqsSettings, Map<String, String> attributes) { |
38 | this.attributes = attributes; | 36 | this.attributes = attributes; |
39 | 37 | ||
40 | - AWSCredentials awsCredentials = new BasicAWSCredentials(sqsSettings.getAccessKeyId(), sqsSettings.getSecretAccessKey()); | 38 | + AWSCredentialsProvider credentialsProvider; |
39 | + if (sqsSettings.getUseDefaultCredentialProviderChain()) { | ||
40 | + credentialsProvider = new DefaultAWSCredentialsProviderChain(); | ||
41 | + } else { | ||
42 | + AWSCredentials awsCredentials = new BasicAWSCredentials(sqsSettings.getAccessKeyId(), sqsSettings.getSecretAccessKey()); | ||
43 | + credentialsProvider = new AWSStaticCredentialsProvider(awsCredentials); | ||
44 | + } | ||
45 | + | ||
41 | sqsClient = AmazonSQSClientBuilder.standard() | 46 | sqsClient = AmazonSQSClientBuilder.standard() |
42 | - .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | 47 | + .withCredentials(credentialsProvider) |
43 | .withRegion(sqsSettings.getRegion()) | 48 | .withRegion(sqsSettings.getRegion()) |
44 | .build(); | 49 | .build(); |
45 | 50 |
@@ -27,6 +27,9 @@ import org.springframework.stereotype.Component; | @@ -27,6 +27,9 @@ import org.springframework.stereotype.Component; | ||
27 | @Data | 27 | @Data |
28 | public class TbAwsSqsSettings { | 28 | public class TbAwsSqsSettings { |
29 | 29 | ||
30 | + @Value("${queue.aws_sqs.use_default_credential_provider_chain}") | ||
31 | + private Boolean useDefaultCredentialProviderChain; | ||
32 | + | ||
30 | @Value("${queue.aws_sqs.access_key_id}") | 33 | @Value("${queue.aws_sqs.access_key_id}") |
31 | private String accessKeyId; | 34 | private String accessKeyId; |
32 | 35 |