ParameterStoreAutoConfiguration breaks application without AWS_REGION (v3.3.0)
Type: Bug
Component: Parameter Store
Describe the bug Our CI build fails when upgrading to version 3.3.0, because the CI build does not provide any AWS settings. The problem ist caused by the ParameterStoreAutoConfiguration (https://github.com/awspring/spring-cloud-aws/pull/1233):
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ssmClient' defined in class path resource [io/awspring/cloud/autoconfigure/config/parameterstore/ParameterStoreAutoConfiguration.class]: Failed to instantiate [software.amazon.awssdk.services.ssm.SsmClient]: Factory method 'ssmClient' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@748e9b20: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@6be25526: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@4a3be6a5: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@46678e49: Unable to contact EC2 metadata service.]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:645) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1361) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:336) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:307) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:334) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.instantiateSingleton(DefaultListableBeanFactory.java:1122) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingleton(DefaultListableBeanFactory.java:1093) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:1030) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:987) ~[spring-context-6.2.2.jar:6.2.2]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.2.2.jar:6.2.2]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752) ~[spring-boot-3.4.2.jar:3.4.2]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439) ~[spring-boot-3.4.2.jar:3.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318) ~[spring-boot-3.4.2.jar:3.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361) ~[spring-boot-3.4.2.jar:3.4.2]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350) ~[spring-boot-3.4.2.jar:3.4.2]
at aws.AwsApplication.main(AwsApplication.java:10) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [software.amazon.awssdk.services.ssm.SsmClient]: Factory method 'ssmClient' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@748e9b20: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@6be25526: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@4a3be6a5: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@46678e49: Unable to contact EC2 metadata service.]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:199) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiateWithFactoryMethod(SimpleInstantiationStrategy.java:88) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:168) ~[spring-beans-6.2.2.jar:6.2.2]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-6.2.2.jar:6.2.2]
... 20 common frames omitted
Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@748e9b20: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@6be25526: Unable to load region from system settings. Region must be specified either via environment variable (AWS_REGION) or system property (aws.region)., software.amazon.awssdk.regions.providers.AwsProfileRegionProvider@4a3be6a5: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@46678e49: Unable to contact EC2 metadata service.]
at software.amazon.awssdk.core.exception.SdkClientException$BuilderImpl.build(SdkClientException.java:111) ~[sdk-core-2.29.52.jar:na]
at software.amazon.awssdk.regions.providers.AwsRegionProviderChain.getRegion(AwsRegionProviderChain.java:70) ~[regions-2.29.52.jar:na]
at io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer.resolveRegion(AwsClientBuilderConfigurer.java:181) ~[spring-cloud-aws-autoconfigure-3.3.0.jar:3.3.0]
at io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer.resolveRegion(AwsClientBuilderConfigurer.java:168) ~[spring-cloud-aws-autoconfigure-3.3.0.jar:3.3.0]
at io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer.configure(AwsClientBuilderConfigurer.java:86) ~[spring-cloud-aws-autoconfigure-3.3.0.jar:3.3.0]
at io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer.configureSyncClient(AwsClientBuilderConfigurer.java:140) ~[spring-cloud-aws-autoconfigure-3.3.0.jar:3.3.0]
at io.awspring.cloud.autoconfigure.config.parameterstore.ParameterStoreAutoConfiguration.ssmClient(ParameterStoreAutoConfiguration.java:58) ~[spring-cloud-aws-autoconfigure-3.3.0.jar:3.3.0]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:171) ~[spring-beans-6.2.2.jar:6.2.2]
... 23 common frames omitted
I expect the AutoConfiguration not to break the application when there are no AWS settings. For now I'll disable the AutoConfiguration as a workaround.
Sample [FAIL] Create a new Spring Boot project, add the spring-cloud-aws-starter-parameter-store dependency and try to start the application without any AWS settings.
[SUCCESS] Then configure the AWS_REGION environment variable and start again.
P.S.: a similar error exists when using the spring-cloud-aws-starter-secrets-manager dependency
Hey @PatrickGotthard , sadly this is problem with all AWS sdks. They fail on create if region is not found.
I recommend turning off autoconfigure or providing region with endpoint in Pipeline. I personally run localstack container in Pipeline and just set region and endpoint of container in pipeline (Using testcontainers) . This way I have full integration tests + close to production env as I can get.
I agree with @MatejNedic. Either exclude AWS dependencies, or use Localstack in integration tests. If anything is unclear, please re-open this issue.