spring-attic / spring-cloud-aws

All development has moved to https://github.com/awspring/spring-cloud-aws Integration for Amazon Web Services APIs with Spring
https://awspring.io/
Apache License 2.0
589 stars 376 forks source link

Ec2MetadataRegionProvider being used even when use-default-aws-region-chain is set to true in application.yml #735

Closed trouptelia closed 3 years ago

trouptelia commented 3 years ago

Type: Bug

Component: "SQS"

Describe the bug Version of Spring Cloud: org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR9 Which resolves to spring cloud aws version 2.2.5.RELEASE spring-cloud-starter-aws-messaging 2.2.5.RELEASE

Our spring boot application is running in ECS Fargate and uses spring-cloud-starter-aws-messaging to access SQS. When the application starts up I see the following error in our logs:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient]: Factory method 'amazonSQS' threw exception; nested exception is java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
--
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650)
... 56 common frames omitted
Caused by: java.lang.IllegalStateException: There is no EC2 meta data available, because the application is not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance
at org.springframework.util.Assert.state(Assert.java:76)
at org.springframework.cloud.aws.core.region.Ec2MetadataRegionProvider.getRegion(Ec2MetadataRegionProvider.java:40)
at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:110)
at org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean.createInstance(AmazonWebserviceClientFactoryBean.java:49)
at org.springframework.beans.factory.config.AbstractFactoryBean.afterPropertiesSet(AbstractFactoryBean.java:142)
at org.springframework.cloud.aws.messaging.config.annotation.SqsClientConfiguration.amazonSQS(SqsClientConfiguration.java:52)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)

Sample I have already set the following in my application.yml:

cloud:
  aws:
    region:
      auto: true
      use-default-aws-region-chain: true
    credentials:
      use-default-aws-credentials-chain: true

As described in PR: #559

This should cause the framework code to use a different region provider but as you can see from the stack trace above this does not seem to work in this case.

maciejwalkowiak commented 3 years ago

I am not able to reproduce this issue. Does this happen only when application runs on ECS or locally too?

Can you provide a minimal sample that suffers from the same problem?

trouptelia commented 3 years ago

My apologies. This was a misconfiguration error on my part. Closing now.

maciejwalkowiak commented 3 years ago

No worries 👍