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

前端 未结 8 1673
遥遥无期
遥遥无期 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 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;
        }
    }
    
    

提交回复
热议问题