Describe the bug I'm trying to override the default AWS endpoint in spring config server by adding this prop : spring.cloud.config.server.awss3.endpoint=http://localhost:4572 but I'm getting error because the AmazonS3 is immutable.

Sample My properties file looks like this :

spring.profiles.active=awss3
spring.cloud.config.server.prefix=config
spring.cloud.config.server.awss3.endpoint=http://localhost:4572
spring.cloud.config.server.awss3.region=us-east-1
spring.cloud.config.server.awss3.bucket=cloud-config-bucket 

and I'm getting this exception :

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.config.server.environment.AwsS3EnvironmentRepository]: Factory method 'awsS3EnvironmentRepository' threw exception; nested exception is java.lang.UnsupportedOperationException: Client is immutable when created with the builder.
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 92 common frames omitted
Caused by: java.lang.UnsupportedOperationException: Client is immutable when created with the builder.
    at com.amazonaws.AmazonWebServiceClient.checkMutability(AmazonWebServiceClient.java:1057) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.AmazonWebServiceClient.setEndpoint(AmazonWebServiceClient.java:316) ~[aws-java-sdk-core-1.11.792.jar:na]
    at com.amazonaws.services.s3.AmazonS3Client.setEndpoint(AmazonS3Client.java:728) ~[aws-java-sdk-s3-1.11.840.jar:na]
    at org.springframework.cloud.config.server.environment.AwsS3EnvironmentRepositoryFactory.build(AwsS3EnvironmentRepositoryFactory.java:42) ~[spring-cloud-config-server-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.cloud.config.server.config.AwsS3RepositoryConfiguration.awsS3EnvironmentRepository(EnvironmentRepositoryConfiguration.java:350) ~[spring-cloud-config-server-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
    ... 93 common frames omitted

I think in AwsS3EnvironmentRepositoryFactory.build the endpoint should be set before actually building the AmazonS3. The builder should use withEndpointConfiguration method https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc//com/amazonaws/client/builder/AwsClientBuilder.html#withEndpointConfiguration-com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration-

Comment From: spencergibb

Please learn how to properly format code and logs.

PRs welcome

Comment From: spencergibb

Duplicates #1871