spring-cloud-aws
spring-cloud-aws copied to clipboard
Spring Application failed to start with error Factory method 'sqsAsyncClient' threw exception with message
Type: Bug
Component: SQS
Describe the bug When trying to start spring application, it throws the following error.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqsAsyncClient' defined in class path resource [io/awspring/cloud/autoconfigure/sqs/SqsAutoConfiguration.class]: Failed to instantiate [software.amazon.awssdk.services.sqs.SqsAsyncClient]: Factory method 'sqsAsyncClient' threw exception with message: Unable to load region from any of the providers in the chain software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain@42f3dac6: [software.amazon.awssdk.regions.providers.SystemSettingsRegionProvider@5b436d8e: 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@7a49293f: No region provided in profile: default, software.amazon.awssdk.regions.providers.InstanceProfileRegionProvider@93f36e0: Unable to contact EC2 metadata service.] at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1330) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:558) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:518) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:325) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.16.jar:6.0.16] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:949) ~[spring-context-6.0.16.jar:6.0.16] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:615) ~[spring-context-6.0.16.jar:6.0.16] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.1.8.jar:3.1.8] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:738) [spring-boot-3.1.8.jar:3.1.8] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:440) [spring-boot-3.1.8.jar:3.1.8] at org.springframework.boot.SpringApplication.run(SpringApplication.java:324) [spring-boot-3.1.8.jar:3.1.8] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1317) [spring-boot-3.1.8.jar:3.1.8] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) [spring-boot-3.1.8.jar:3.1.8]
@praveendev18 have you configured the AWS region?
https://docs.awspring.io/spring-cloud-aws/docs/3.1.0/reference/html/index.html#region
This is a Jenkins job which is trying to test the application. If I set spring.cloud.aws.region.static value will this work?
If deployed in some other region and we specify AWS_REGION, which will take precedence?
spring.cloud.aws.region.static or AWS_REGION?
This part will work if you set region statically but I don't know what happens then in your application.
If it's for testing, perhaps you can consider using Localstack with Testcontainers and then resolve region from the container.
Closing due to lack of feedback