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,440 points
52 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,090 points

Related Questions In AWS

0 votes
1 answer
+1 vote
2 answers

How do I get my AWS Glue client in JAVA?

Hey, you've been using a correct code ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,260 points
774 views
+1 vote
2 answers

How do I run python script on aws EC2 instance(ubuntu)?

I believe that you are using the ...READ MORE

answered Apr 17, 2018 in AWS by Cloud gunner
• 4,260 points
1,640 views
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,050 points
476 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,810 points
56 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,380 points
336 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
• 14,080 points
38 views
0 votes
1 answer

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

On Amazon Linux AMIs you can do: $ ...READ MORE

answered Sep 10, 2018 in AWS by Archana
• 4,090 points
21 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,090 points
440 views