Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the public ip of current ec2 instance in python?

How to obtain the public ip address of the current EC2 instance in python ?

like image 791
Dharmanshu Kamra Avatar asked Aug 31 '14 05:08

Dharmanshu Kamra


People also ask

How do I find my EC2 instance public IP?

To view the IPv4 addresses for an instance using the consoleOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Instances and select your instance. The following information is available on the Networking tab: Public IPv4 address — The public IPv4 address.

How do I get a public IP address AWS?

To allocate and associate an Elastic IP address with your EC2 Windows or Linux instance, follow these steps: Allocate an Elastic IP address from either Amazon's pool of public IPv4 addresses or a custom IP address pool that you bring to your AWS account. Associate the Elastic IP address with a running instance.


1 Answers

import urllib.request
urllib.request.urlopen("http://169.254.169.254/latest/meta-data/public-ipv4").read()
like image 115
Robert Harvey Avatar answered Oct 03 '22 13:10

Robert Harvey