AWS应用程序的春季启动启动错误:没有可用的EC2元数据 [英] Spring boot startup error for AWS application : There is not EC2 meta data available

查看:215
本文介绍了AWS应用程序的春季启动启动错误:没有可用的EC2元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在本地运行Spring boot-AWS应用程序时出现以下错误:

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

没有可用的EC2元数据,因为该应用程序未在EC2环境中运行.仅当应用程序在EC2实例上运行时,才可以进行区域检测

我的aws-config.xml如下所示:

My aws-config.xml looks like below :

  <aws-context:context-credentials>
     <aws-context:simple-credentials access-key="*****" secret-key="*****"/>
  </aws-context:context-credentials>  
    <aws-context:context-region auto-detect="false" region="ap-south-1" />  
 <aws-context:context-resource-loader/>  
 <aws-messaging:annotation-driven-queue-listener max-number-of-messages="10" wait-time-out="20" visibility-timeout="3600"/> 

我正尝试在下面的类中使用SQSListner进行监听:

I am trying to listen with a SQSListner in the below class :

 @Configuration
 @EnableSqs
 @ImportResource("classpath:/aws-config.xml")
 @EnableRdsInstance(databaseName = "******", 
               dbInstanceIdentifier = "*****", 
               password = "******")
 public class AwsResourceConfig {
@SqsListener(value = "souviksqs", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
public void receiveNewFileUpload(S3EventNotification event) {
    try {
        if ( event != null && !CollectionUtils.isNullOrEmpty( event.getRecords() ) && event.getRecords().get( 0 ) != null ) {
            S3Entity entry = event.getRecords().get(0).getS3();
            System.out.println("############ File Uploaded to ###################### " + entry.getBucket().getName() + "/" + entry.getObject().getKey());
        }
    } catch (Exception e) {
        System.out.println("Error reading the SQS message " + e);

    }
}

}

刚刚注意到,当我包含以下aws-messaging maven依赖项时,就会出现错误:

Edit : Just noticed that the error comes when I include the following aws-messaging maven dependency :

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-aws-messaging</artifactId>
         <version>${spring-cloud-aws-version}</version>
    </dependency>

我正在使用spring-cloud-aws-version-1.2.1发布

I am using spring-cloud-aws-version - 1.2.1.RELEASE

推荐答案

发现了问题. 我正在使用 spring-cloud-starter-aws-messaging 进行SQS消息传递. 上述依赖项包括许多自动检测类,即使它们不是必需的,它们最终也会触发.

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.

相反,我使用了 spring-cloud-aws-messaging 来解决该问题以及许多其他自动检测问题.

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

这篇关于AWS应用程序的春季启动启动错误:没有可用的EC2元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆