How do i get the Elastic IP from running instance

0 votes

I am running a  java application running on an EC2 instance. I want to know what my own elastic IP address that was manually assigned from the management console. Is there a way to query EC2 API for this?

Aug 29, 2018 in AWS by datageek
• 2,540 points
1,848 views

1 answer to this question.

0 votes

If yours is a linux ec2 instance this should work:

Command:

curl http://169.254.169.254/latest/meta-data/public-ipv4

Java Code:

public static String getIP() throws IOException, InterruptedException {
    Process p = Runtime.getRuntime().exec("curl http://169.254.169.254/latest/meta-data/public-ipv4");
    int returnCode = p.waitFor();
    if ( returnCode == 0 ) {
        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String ip = r.readLine();
        r.close();
        return ip;
    }
    else {
        //handle error
        return null;
    }
}

answered Aug 29, 2018 by Archana
• 4,170 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Unable to connect to chromedriver 127.0.0.1:9515 on Amazon Linux AMI server

The issue seems to be only with ...READ MORE

answered Mar 26, 2018 in Selenium by nsv999
• 5,500 points
2,503 views
+3 votes
1 answer

aws cloudformation for atomic stack-update

When you perform a stack update, only ...READ MORE

answered Mar 27, 2018 in AWS by DareDev
• 6,890 points
1,127 views
+5 votes
2 answers

EC2 instance status check failed

Creating a snapshot from an EBS volume ...READ MORE

answered Mar 27, 2018 in AWS by DragonLord999
• 8,450 points
3,078 views
+1 vote
3 answers

How can I connect an app with an aws ec2 instance?

This is how you deploy a web ...READ MORE

answered Oct 18, 2018 in DevOps & Agile by Hannah
• 18,520 points
2,368 views
0 votes
2 answers

How can I find out the instance id of an ec2 instance from within the ec2 instance?

A curl or wget to http://169.254.169.254/latest/meta-data/instance-id will ...READ MORE

answered Mar 9, 2020 in AWS by anonymous
6,971 views
0 votes
1 answer

How to copy a folder from S3 to Elastic Beanstalk instance on its creation?

I had encountered similar problem. But i ...READ MORE

answered Aug 24, 2018 in AWS by Archana
• 4,170 points
4,620 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP