Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

amazon web services - Spring boot startup error for AWS application : There is not EC2 meta data available

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

question from:https://stackoverflow.com/questions/45818092/spring-boot-startup-error-for-aws-application-there-is-not-ec2-meta-data-avail

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...