List public IP addresses of EC2 instances
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
In Amazon Web Services (AWS), Elastic Compute Cloud (EC2) is a core service that provides scalable computing capacity in the cloud. Each EC2 instance can be associated with public and private IP addresses, playing a crucial role in networking and communication. Public IPs allow instances to be accessible over the Internet. This article delves into how to list public IP addresses of EC2 instances using various AWS tools and interfaces.
Understanding EC2 Public IP Addresses
An EC2 instance can be assigned a public IP address based on its subnet configuration:
- Public Subnet: Instances receive a public IP by default. This enables Internet traffic, governed by a route table with an Internet Gateway.
- Private Subnet: Instances do not receive a public IP and usually require a NAT gateway for Internet-bound traffic.
Elastic IP Addresses
Elastic IP (EIP) is a static IPv4 address designed for dynamic cloud computing. It can be allocated to an AWS account and associated with EC2 instances. An EIP is retained in your account until explicitly released.
Methods to List Public IPs of EC2 Instances
There are several methods to list public IP addresses using AWS tools.
Using AWS Management Console
- Navigate to EC2 Dashboard: Go to the AWS Management Console and access the EC2 dashboard.
- Instances Section: Click on "Instances" to list all instances.
- Public IP Visibility: The "Public IP" column displays the public IPs of each instance.
Using AWS CLI
The AWS Command Line Interface (CLI) is a versatile tool for managing AWS services.
- This command provides a table view of Instance IDs and their corresponding public IP addresses.
- Based on AWS CLI versioning, ensure you use
--queryoption properly for structured query requests. - Session Control: Set your AWS credentials and region to establish a connection to EC2.
- Instance Iteration: Loop through instances to extract the public IP attribute.
- Public IP Addresses are dynamic and can change if the instance is stopped and started.
- Elastic IP Addresses remain constant unless manually reassigned or released.
- While public IPs are typically costless, allocating more than one Elastic IP incurs charges.
- Cost management is vital when using IPs extensively in enterprise settings.
- Limiting access to instances via public IPs enhances security posture.
- Use security groups and network ACLs to manage incoming traffic efficiently.
Related reading
- Listing contents of a bucket with boto3
- Listing contents of a bucket with boto3
- Listing files in a specific folder of a AWS S3 bucket
- Listing just the sub folders in an s3 bucket
- Listing all deployed rest endpoints spring-boot, jersey
- Liveness probe with http post
- Load S3 Data into AWS SageMaker Notebook
- Load S3 Data into AWS SageMaker Notebook

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.