Skip to content
Advertisement

How to disable AWS parameter store autoconfiguration for tests?

I have added spring-cloud-starter-aws-parameter-store-config dependency as explained in the spring documentation. Now, for unit tests I want to disable parameter store configuration. But not able to do it.

I tried setting following property in test/application.properties

 aws.paramstore.enabled=false

Also tried excluding AwsParamStoreBootstrapConfiguration.class from AutoConfiguration but still not working.

Exception

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement]: Factory method ‘ssmClient’ threw exception; nested exception is com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] … 83 common frames omitted Caused by: com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region. at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371) ~[aws-java-sdk-core-1.11.336.jar:na] at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337) ~[aws-java-sdk-core-1.11.336.jar:na] at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46) ~[aws-java-sdk-core-1.11.336.jar:na] at com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder.defaultClient(AWSSimpleSystemsManagementClientBuilder.java:44) ~[aws-java-sdk-ssm-1.11.336.jar:na] at org.springframework.cloud.aws.autoconfigure.paramstore.AwsParamStoreBootstrapConfiguration.ssmClient(AwsParamStoreBootstrapConfiguration.java:53) ~[spring-cloud-starter-aws-parameter-store-config-2.0.0.RELEASE.jar:2.0.0.RELEASE]

Advertisement

Answer

I was able to disable paramstore with alternative approach by adding the property (aws.paramstore.enabled=false) to bootstrap.properties file test resources folder. This one is much simpler solution

Older solution

I was able to figure out the solution. Seems that SpringBootTest tries to load ssmClient even before the test configuration class, and before loading application.properties. The solution is to disable paramstore by specifying the property on @SpringBootTest itself

@SpringBootTest(classes = MyApp.class, properties = {"aws.paramstore.enabled=false"})
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement