Spring boot startup error for AWS application : There is not EC2 meta data available

前端 未结 8 1563
遥遥无期
遥遥无期 2021-01-07 16:43

I am getting the below error when I am trying to run a Spring boot-AWS application locally :

There is not EC2 meta data available, because the application is

相关标签:
8条回答
  • 2021-01-07 16:50

    Found the Issue. I was using spring-cloud-starter-aws-messaging for SQS messaging. The above dependency includes many Auto Detect classes which eventually was firing up even if they were not required.

    Instead I have used spring-cloud-aws-messaging which solved the issue along with many other auto detect issues.

    0 讨论(0)
  • 2021-01-07 16:54

    I had the same issue and I was able to prevent spring cloud aws from auto configuring the region by adding this exclude on the Spring configuration.

        @SpringBootApplication(exclude = ContextRegionProviderAutoConfiguration.class)
    
    0 讨论(0)
  • 2021-01-07 16:55

    I was using springframework.cloud.aws.autoconfigure, got the same problem. The reason behind it is, we need to configure region manually when we run application in NON AWS ENVIRONMENT, ie. Local. So put this property in your application-local.properties and you should be good.

    cloud.aws.region.static=us-east-1
    
    0 讨论(0)
  • 2021-01-07 17:00

    If using application.yml I did it with the following

    spring:
      application:
        name: App Name
      autoconfigure:
        exclude:
          - org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
          - org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
          - org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
    
    0 讨论(0)
  • 2021-01-07 17:00

    I also faced the same issue but it did not get resolved after adding the aws region property. I was able to resolved the same when I removed spring-cloud-starter-aws dependency from my pom

    0 讨论(0)
  • 2021-01-07 17:10

    This proved a little tricky for me to solve.

    Using the information from souvikc above: https://stackoverflow.com/a/45853793/1279002

    and

    here: https://stackoverflow.com/a/55255504/1279002

    I came up with (I'll take the hard coded region out eventually but just elated it finally works!):

    
    @Configuration
    @EnableContextInstanceData
    @EnableSqs
    @Profile("!local")
    @Slf4j
    public class AwsEc2Config {
    
        @Bean
        public RegionProvider regionProvider() {
            return new StaticRegionProvider("eu-west-1");
        }
    
        @Bean
        public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory(AmazonSQSAsync amazonSQS) {
            SimpleMessageListenerContainerFactory factory = new SimpleMessageListenerContainerFactory();
            factory.setAmazonSqs(amazonSQS);
            factory.setMaxNumberOfMessages(10);
            factory.setAutoStartup(true);
            factory.setWaitTimeOut(20);
    
            return factory;
        }
    }
    
    
    0 讨论(0)
提交回复
热议问题