1ntgr
1ntgr

Reputation: 126

Return list of _all_ ip addresses using AWS CLI

Using the AWS CLI, I'd like to retrieve a list of all IP addresses, whether EIP or statically assigned etc.

I've been using describe-instances and describe-addresses but want to know if there is an easier way to get all public IP addresses?

aws ec2 describe-addresses --public-ips --region eu-west-1 --query 'Addresses[*].PublicIp'

aws ec2 describe-instances --region eu-west-1

I've searched through the AWS documentation, but haven't found anything that encompasses everything.

Upvotes: 3

Views: 4539

Answers (2)

sktan
sktan

Reputation: 1259

You will likely be able to retrieve most of the IP addresses from multiple services by calling the AWS EC2 ENI API: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-interfaces.html

This will gather all IP addresses in for supported services and output them for you.

aws ec2 describe-network-interfaces --query "NetworkInterfaces[*][].PrivateIpAddresses[*][].{Private: PrivateIpAddress, Public: Association.PublicIp}"

Upvotes: 3

John Rotenstein
John Rotenstein

Reputation: 270184

No, there is no "overall" command you could run. Each service has its own API.

Please note that many services will have IP addresses that change. For example, an Elastic Load Balancer will use many IP addresses and should always be addressed by its DNS Name rather than by IP address.

Upvotes: 1

Related Questions