Skip to content

Commit aeed5db

Browse files
Add ability to provide custom client configuration (spring-attic/spring-cloud-aws#725)
Closes spring-attic/spring-cloud-aws#412 Closes spring-attic/spring-cloud-aws#63
1 parent d807cbe commit aeed5db

22 files changed

+861
-61
lines changed
Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,68 @@
11
|===
22
|Name | Default | Description
33

4-
|aws.paramstore.default-context | application |
5-
|aws.paramstore.enabled | true | Is AWS Parameter Store support enabled.
4+
|aws.paramstore.default-context | `application` |
5+
|aws.paramstore.enabled | `true` | Is AWS Parameter Store support enabled.
66
|aws.paramstore.endpoint | | Overrides the default endpoint.
7-
|aws.paramstore.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings.
7+
|aws.paramstore.fail-fast | `true` | Throw exceptions during config lookup if true, otherwise, log warnings.
88
|aws.paramstore.name | | Alternative to spring.application.name to use in looking up values in AWS Parameter Store.
9-
|aws.paramstore.prefix | /config | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config".
10-
|aws.paramstore.profile-separator | _ |
9+
|aws.paramstore.prefix | `/config` | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config".
10+
|aws.paramstore.profile-separator | `_` |
1111
|aws.paramstore.region | | If region value is not null or empty it will be used in creation of AWSSimpleSystemsManagement.
12-
|aws.secretsmanager.default-context | application |
13-
|aws.secretsmanager.enabled | true | Is AWS Secrets Manager support enabled.
12+
|aws.secretsmanager.default-context | `application` |
13+
|aws.secretsmanager.enabled | `true` | Is AWS Secrets Manager support enabled.
1414
|aws.secretsmanager.endpoint | | Overrides the default endpoint.
15-
|aws.secretsmanager.fail-fast | true | Throw exceptions during config lookup if true, otherwise, log warnings.
15+
|aws.secretsmanager.fail-fast | `true` | Throw exceptions during config lookup if true, otherwise, log warnings.
1616
|aws.secretsmanager.name | | Alternative to spring.application.name to use in looking up values in AWS Secrets Manager.
17-
|aws.secretsmanager.prefix | /secret | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config".
18-
|aws.secretsmanager.profile-separator | _ |
17+
|aws.secretsmanager.prefix | `/secret` | Prefix indicating first level for every property. Value must start with a forward slash followed by a valid path segment or be empty. Defaults to "/config".
18+
|aws.secretsmanager.profile-separator | `_` |
1919
|aws.secretsmanager.region | | If region value is not null or empty it will be used in creation of AWSSecretsManager.
2020
|cloud.aws.credentials.access-key | | The access key to be used with a static provider.
21-
|cloud.aws.credentials.instance-profile | false | Configures an instance profile credentials provider with no further configuration.
21+
|cloud.aws.credentials.instance-profile | `false` | Configures an instance profile credentials provider with no further configuration.
2222
|cloud.aws.credentials.profile-name | | The AWS profile name.
2323
|cloud.aws.credentials.profile-path | | The AWS profile path.
2424
|cloud.aws.credentials.secret-key | | The secret key to be used with a static provider.
25-
|cloud.aws.elasticache.cache-names | |
25+
|cloud.aws.elasticache.cache-names | |
2626
|cloud.aws.elasticache.clusters | | Configures the cache clusters for the caching configuration. Support one or multiple caches {@link Cluster} configurations with their physical cache name (as configured in the ElastiCache service) or their logical cache name if the caches are configured inside a stack and {@link org.springframework.cloud.aws.context.config.annotation.EnableStackConfiguration} annotation is used inside the application.
27-
|cloud.aws.elasticache.default-expiration | 0 | Configures the default expiration time in seconds if there is no custom expiration time configuration with a {@link Cluster} configuration for the cache. The expiration time is implementation specific (e.g. Redis or Memcached) and could therefore differ in the behaviour based on the cache implementation.
28-
|cloud.aws.elasticache.enabled | true | Enables ElastiCache integration.
29-
|cloud.aws.elasticache.expiry-time-per-cache | |
30-
|cloud.aws.instance.data.enabled | false | Enables Instance Data integration.
31-
|cloud.aws.loader.core-pool-size | 1 | The core pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setCorePoolSize(int)
27+
|cloud.aws.elasticache.default-expiration | `0` | Configures the default expiration time in seconds if there is no custom expiration time configuration with a {@link Cluster} configuration for the cache. The expiration time is implementation specific (e.g. Redis or Memcached) and could therefore differ in the behaviour based on the cache implementation.
28+
|cloud.aws.elasticache.enabled | `true` | Enables ElastiCache integration.
29+
|cloud.aws.elasticache.expiry-time-per-cache | |
30+
|cloud.aws.instance.data.enabled | `false` | Enables Instance Data integration.
31+
|cloud.aws.loader.core-pool-size | `1` | The core pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setCorePoolSize(int)
3232
|cloud.aws.loader.max-pool-size | | The maximum pool size of the Task Executor used for parallel S3 interaction. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setMaxPoolSize(int)
3333
|cloud.aws.loader.queue-capacity | | The maximum queue capacity for backed up S3 requests. @see org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#setQueueCapacity(int)
34-
|cloud.aws.mail.enabled | true | Enables Mail integration.
35-
|cloud.aws.mail.endpoint | |
36-
|cloud.aws.mail.region | |
37-
|cloud.aws.rds.enabled | true | Enables RDS integration.
38-
|cloud.aws.rds.endpoint | |
34+
|cloud.aws.mail.enabled | `true` | Enables Mail integration.
35+
|cloud.aws.mail.endpoint | |
36+
|cloud.aws.mail.region | |
37+
|cloud.aws.rds.enabled | `true` | Enables RDS integration.
38+
|cloud.aws.rds.endpoint | |
3939
|cloud.aws.rds.instances | | List of RdsInstances.
40-
|cloud.aws.rds.region | |
40+
|cloud.aws.rds.region | |
41+
|cloud.aws.region.static | |
4142
|cloud.aws.s3.endpoint | | Overrides the default endpoint.
4243
|cloud.aws.s3.region | | Overrides the default region.
43-
|cloud.aws.sns.enabled | true | Enables SNS integration.
44-
|cloud.aws.sns.endpoint | |
45-
|cloud.aws.sns.region | |
46-
|cloud.aws.sqs.enabled | true | Enables SQS integration.
47-
|cloud.aws.sqs.endpoint | |
44+
|cloud.aws.sns.enabled | `true` | Enables SNS integration.
45+
|cloud.aws.sns.endpoint | |
46+
|cloud.aws.sns.region | |
47+
|cloud.aws.sqs.enabled | `true` | Enables SQS integration.
48+
|cloud.aws.sqs.endpoint | |
4849
|cloud.aws.sqs.handler.default-deletion-policy | | Configures global deletion policy used if deletion policy is not explicitly set on {@link SqsListener}.
49-
|cloud.aws.sqs.listener.auto-startup | true | Configures if this container should be automatically started.
50+
|cloud.aws.sqs.listener.auto-startup | `true` | Configures if this container should be automatically started.
5051
|cloud.aws.sqs.listener.back-off-time | | The number of milliseconds the polling thread must wait before trying to recover when an error occurs (e.g. connection timeout).
51-
|cloud.aws.sqs.listener.max-number-of-messages | 10 | The maximum number of messages that should be retrieved during one poll to the Amazon SQS system. This number must be a positive, non-zero number that has a maximum number of 10. Values higher then 10 are currently not supported by the queueing system.
52+
|cloud.aws.sqs.listener.max-number-of-messages | `10` | The maximum number of messages that should be retrieved during one poll to the Amazon SQS system. This number must be a positive, non-zero number that has a maximum number of 10. Values higher then 10 are currently not supported by the queueing system.
5253
|cloud.aws.sqs.listener.queue-stop-timeout | | The queue stop timeout that waits for a queue to stop before interrupting the running thread.
5354
|cloud.aws.sqs.listener.visibility-timeout | | The duration (in seconds) that the received messages are hidden from subsequent poll requests after being retrieved from the system.
54-
|cloud.aws.sqs.listener.wait-timeout | 20 | The wait timeout that the poll request will wait for new message to arrive if the are currently no messages on the queue. Higher values will reduce poll request to the system significantly. The value should be between 1 and 20. For more information read the <a href= "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">documentation</a>.
55-
|cloud.aws.sqs.region | |
56-
|cloud.aws.stack.auto | true | Enables the automatic stack name detection for the application.
57-
|cloud.aws.stack.enabled | true | Enables Stack integration.
55+
|cloud.aws.sqs.listener.wait-timeout | `20` | The wait timeout that the poll request will wait for new message to arrive if the are currently no messages on the queue. Higher values will reduce poll request to the system significantly. The value should be between 1 and 20. For more information read the <a href= "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">documentation</a>.
56+
|cloud.aws.sqs.region | |
57+
|cloud.aws.stack.auto | `true` | Enables the automatic stack name detection for the application.
58+
|cloud.aws.stack.enabled | `true` | Enables Stack integration.
5859
|cloud.aws.stack.name | | The name of the manually configured stack name that will be used to retrieve the resources.
59-
|spring.cloud.aws.security.cognito.algorithm | RS256 | Encryption algorithm used to sign the JWK token.
60+
|spring.cloud.aws.security.cognito.algorithm | `RS256` | Encryption algorithm used to sign the JWK token.
6061
|spring.cloud.aws.security.cognito.app-client-id | | Non-dynamic audience string to validate.
61-
|spring.cloud.aws.security.cognito.enabled | true | Enables Cognito integration.
62-
|spring.cloud.aws.security.cognito.region | |
63-
|spring.cloud.aws.security.cognito.user-pool-id | |
64-
|spring.cloud.aws.ses.enabled | true | Enables Simple Email Service integration.
62+
|spring.cloud.aws.security.cognito.enabled | `true` | Enables Cognito integration.
63+
|spring.cloud.aws.security.cognito.region | |
64+
|spring.cloud.aws.security.cognito.user-pool-id | |
65+
|spring.cloud.aws.ses.enabled | `true` | Enables Simple Email Service integration.
6566
|spring.cloud.aws.ses.region | | Overrides the default region.
6667

67-
|===
68+
|===

docs/src/main/asciidoc/spring-cloud-aws.adoc

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,72 @@ cloud.aws.rds.endpoint=http://localhost:4566
383383

384384
Using custom endpoint can be especially useful when using https://github.com/localstack/localstack[Localstack] in integration tests or integrating with AWS compatible 3rd party services like https://min.io/[MinIO].
385385

386+
===== Configuring client configuration
387+
388+
For some AWS service integrations you can configure Spring Cloud AWS to use custom `ClientConfiguration`.
389+
390+
To override the default `ClientConfiguration` used by all integrations, create a bean of type `ClientConfiguration` with a name `com.amazonaws.ClientConfiguration.BEAN_NAME`.
391+
392+
[source,java,indent=0]
393+
----
394+
@Configuration
395+
class CustomAwsConfiguration {
396+
397+
@Bean(name = "com.amazonaws.ClientConfiguration.BEAN_NAME")
398+
ClientConfiguration clientConfiguration() {
399+
ClientConfiguration clientConfiguration= new ClientConfiguration();
400+
clientConfiguration.setProxyHost(proxyHost);
401+
clientConfiguration.setProxyPort(proxyPort);
402+
clientConfiguration.setProxyUsername(proxyUserName);
403+
clientConfiguration.setProxyPassword(proxyPassword);
404+
return clientConfiguration;
405+
}
406+
}
407+
----
408+
409+
It's also possible to provide `ClientConfiguration` for particular integration by defining a bean of type `ClientConfiguration` and a name specific to the integration:
410+
411+
[cols="2"]
412+
|===
413+
| SQS
414+
| `sqsClientConfiguration`
415+
416+
| SNS
417+
| `snsClientConfiguration`
418+
419+
| SES
420+
| `sesClientConfiguration`
421+
422+
| RDS
423+
| `rdsClientConfiguration`
424+
425+
| ElastiCache
426+
| `elastiCacheClientConfiguration`
427+
428+
| CloudWatch
429+
| `cloudWatchClientConfiguration`
430+
431+
|===
432+
433+
For example:
434+
435+
[source,java,indent=0]
436+
----
437+
@Configuration
438+
class CustomSqsConfiguration {
439+
440+
@Bean
441+
ClientConfiguration sqsClientConfiguration() {
442+
ClientConfiguration clientConfiguration= new ClientConfiguration();
443+
clientConfiguration.setProxyHost(proxyHost);
444+
clientConfiguration.setProxyPort(proxyPort);
445+
clientConfiguration.setProxyUsername(proxyUserName);
446+
clientConfiguration.setProxyPassword(proxyPassword);
447+
return clientConfiguration;
448+
}
449+
}
450+
----
451+
386452
== Cloud environment
387453
Applications often need environment specific configuration information, especially in changing environments like in the
388454
Amazon cloud environment. Spring Cloud AWS provides a support to retrieve and use environment specific data inside the

spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/cache/ElastiCacheAutoConfiguration.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import com.amazonaws.ClientConfiguration;
2223
import com.amazonaws.auth.AWSCredentialsProvider;
2324
import com.amazonaws.services.elasticache.AmazonElastiCache;
2425
import com.amazonaws.services.elasticache.AmazonElastiCacheClient;
2526
import net.spy.memcached.MemcachedClient;
2627

2728
import org.springframework.beans.factory.ObjectProvider;
29+
import org.springframework.beans.factory.annotation.Qualifier;
2830
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2931
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3032
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -46,6 +48,8 @@
4648
import org.springframework.context.annotation.Import;
4749
import org.springframework.data.redis.connection.RedisConnectionFactory;
4850

51+
import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.GLOBAL_CLIENT_CONFIGURATION_BEAN_NAME;
52+
4953
/**
5054
* @author Agim Emruli
5155
* @author Eddú Meléndez
@@ -62,18 +66,24 @@ public class ElastiCacheAutoConfiguration {
6266

6367
private final ListableStackResourceFactory stackResourceFactory;
6468

69+
private final ClientConfiguration clientConfiguration;
70+
6571
public ElastiCacheAutoConfiguration(ElastiCacheProperties properties,
66-
ObjectProvider<ListableStackResourceFactory> stackResourceFactory) {
72+
ObjectProvider<ListableStackResourceFactory> stackResourceFactory,
73+
@Qualifier(GLOBAL_CLIENT_CONFIGURATION_BEAN_NAME) ObjectProvider<ClientConfiguration> globalClientConfiguration,
74+
@Qualifier("elastiCacheClientConfiguration") ObjectProvider<ClientConfiguration> elastiCacheClientConfiguration) {
6775
this.properties = properties;
6876
this.stackResourceFactory = stackResourceFactory.getIfAvailable();
77+
this.clientConfiguration = elastiCacheClientConfiguration
78+
.getIfAvailable(globalClientConfiguration::getIfAvailable);
6979
}
7080

7181
@Bean
7282
@ConditionalOnMissingBean(AmazonElastiCache.class)
7383
public AmazonWebserviceClientFactoryBean<AmazonElastiCacheClient> amazonElastiCache(
7484
ObjectProvider<RegionProvider> regionProvider, ObjectProvider<AWSCredentialsProvider> credentialsProvider) {
7585
return new AmazonWebserviceClientFactoryBean<>(AmazonElastiCacheClient.class,
76-
credentialsProvider.getIfAvailable(), regionProvider.getIfAvailable());
86+
credentialsProvider.getIfAvailable(), regionProvider.getIfAvailable(), clientConfiguration);
7787
}
7888

7989
@Bean

spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/jdbc/AmazonRdsDatabaseAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
8181
String endpoint = properties.getEndpoint() != null ? properties.getEndpoint().toString() : null;
8282
String amazonRdsClientBeanName = AmazonWebserviceClientConfigurationUtils
8383
.registerAmazonWebserviceClient(this, registry, "com.amazonaws.services.rds.AmazonRDSClient", null,
84-
properties.getRegion(), endpoint)
84+
properties.getRegion(), endpoint, "rdsClientConfiguration")
8585
.getBeanName();
8686
properties.getInstances().stream().filter(RdsInstance::hasRequiredPropertiesSet)
8787
.forEach(instance -> registerDatasource(registry, amazonRdsClientBeanName, instance));

spring-cloud-aws-autoconfigure/src/main/java/org/springframework/cloud/aws/autoconfigure/mail/SesAutoConfiguration.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818

1919
import javax.mail.Session;
2020

21+
import com.amazonaws.ClientConfiguration;
2122
import com.amazonaws.auth.AWSCredentialsProvider;
2223
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
2324
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
2425

2526
import org.springframework.beans.factory.ObjectProvider;
27+
import org.springframework.beans.factory.annotation.Qualifier;
2628
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2729
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
2830
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -45,6 +47,8 @@
4547
import org.springframework.mail.MailSender;
4648
import org.springframework.mail.javamail.JavaMailSender;
4749

50+
import static org.springframework.cloud.aws.core.config.AmazonWebserviceClientConfigurationUtils.GLOBAL_CLIENT_CONFIGURATION_BEAN_NAME;
51+
4852
/**
4953
* {@link EnableAutoConfiguration Auto-configuration} for AWS Simple Email Service
5054
* support.
@@ -66,18 +70,24 @@ public class SesAutoConfiguration {
6670

6771
private final RegionProvider regionProvider;
6872

73+
private final ClientConfiguration clientConfiguration;
74+
6975
public SesAutoConfiguration(ObjectProvider<RegionProvider> regionProvider,
70-
ObjectProvider<AWSCredentialsProvider> credentialsProvider, SesProperties properties) {
76+
ObjectProvider<AWSCredentialsProvider> credentialsProvider,
77+
@Qualifier(GLOBAL_CLIENT_CONFIGURATION_BEAN_NAME) ObjectProvider<ClientConfiguration> globalClientConfiguration,
78+
@Qualifier("sesClientConfiguration") ObjectProvider<ClientConfiguration> sesClientConfiguration,
79+
SesProperties properties) {
7180
this.credentialsProvider = credentialsProvider.getIfAvailable();
7281
this.regionProvider = properties.getRegion() == null ? regionProvider.getIfAvailable()
7382
: new StaticRegionProvider(properties.getRegion());
83+
this.clientConfiguration = sesClientConfiguration.getIfAvailable(globalClientConfiguration::getIfAvailable);
7484
}
7585

7686
@Bean
7787
@ConditionalOnMissingAmazonClient(AmazonSimpleEmailService.class)
7888
public AmazonWebserviceClientFactoryBean<AmazonSimpleEmailServiceClient> amazonSimpleEmailService() {
7989
return new AmazonWebserviceClientFactoryBean<>(AmazonSimpleEmailServiceClient.class, this.credentialsProvider,
80-
this.regionProvider);
90+
this.regionProvider, this.clientConfiguration);
8191
}
8292

8393
@Bean

0 commit comments

Comments
 (0)