0

I have created a simple springboot application that just sends a message to SQS. while starting the app, it is trying to connect to EC2 metadata instance and failing, I tried to set that to false, but it still fails with different error message. Can someone please help me understand what am I missing.

build.gradle file with the dependencies,I tried with multiple spring boot version also

plugins {
    id 'org.springframework.boot' version '2.0.5.RELEASE'
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
    id 'java'
    id 'war'
}

group = 'com.springboot.aws.ebs'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}
dependencyManagement {
    imports {
        mavenBom 'com.amazonaws:aws-java-sdk-bom:1.10.47'
        //mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

dependencies {
    compile 'com.amazonaws:aws-java-sdk-s3'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compile group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.890'
    compile group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.890'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-aws', version: '2.1.2.RELEASE'
    compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-aws-messaging', version: '2.1.2.RELEASE'
    providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

application.yml file I used to configure the connection details

cloud:
  aws:
    region:
      static: <region>
      auto: false
    credentials:
      access-key: <access key>
      secret-key: <secret key>
    end-point:
      uri: <end-point>

I looked into a few stackoverflow post with the same issue, but none of them helped. thanks in advance for your help.

Error Details

com.amazonaws.SdkClientException: Failed to connect to service endpoint:

it tries to connect to EC2 metadata instance (http://169.254.169.254)

Caused by: java.net.ConnectException: Host is down (connect failed)

Amit Agarwal
  • 191
  • 1
  • 3
  • 11
  • If you log into the machine and do a `curl http://169.254.169.254` are you able to see a 404 page? And, more interestingly, can you get something like `curl http://169.254.169.254/latest/meta-data/instance-type`? – stdunbar Nov 03 '20 at 04:03
  • Yes I did that...I am getting error (curl https://169.254.169.254/) -- Couldn't connect to server, when I did (curl http://169.254.169.254/latest/meta-data/instance-type) it does not return any response. – Amit Agarwal Nov 03 '20 at 04:27
  • I tried to follow https://stackoverflow.com/questions/60966289/how-to-run-the-app-with-spring-cloud-starter-aws-locally but still issue did not get resolved. – Amit Agarwal Nov 04 '20 at 04:14
  • If you can't access this with `curl` then no amount of Java configuration will help. Do you have any firewall setup that might block that? Or do you have something in your startup script that may have changed the networking? And what O/S are you running? [Windows seems to have some issues](https://stackoverflow.com/questions/59493723/timeout-when-trying-to-retrieve-ec2-instance-id-metadata-from-within-it) with the Windows firewall. – stdunbar Nov 04 '20 at 14:47

0 Answers0