Warm tip: This article is reproduced from stackoverflow.com, please click
amazon-web-services spring-boot aws-sdk

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

发布于 2020-03-28 23:14:20

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 not running in the EC2 environment. Region detection is only possible if the application is running on a EC2 instance

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"/> 

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);

    }
}

}

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>

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

Questioner
souvikc
Viewed
123
souvikc 2017-08-24 13:44

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.