温馨提示:本文翻译自stackoverflow.com,查看原文请点击:amazon web services - Spring boot startup error for AWS application : There is not EC2 meta data available
amazon-web-services spring-boot aws-sdk

amazon web services - AWS应用程序的 Spring 启动启动错误:没有可用的EC2元数据

发布于 2020-03-28 23:27:36

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

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

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

  <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进行监听:

 @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依赖项时,就会出现错误:

<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.RELEASE

查看更多

查看更多

提问者
souvikc
被浏览
148
souvikc 2017-08-24 13:44

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

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