0 votes
1 view
in AWS by (9.2k points)

Using Amazon CLI, is there a way to get the public ip address of the current EC2? I'm just looking for the single string value, so not the json response describe-addresses returns.

1 Answer

0 votes
by (18.5k points)

You can use ec2 describe instances command in AWS CLI to display information about your running instances. 

Run the following command in your AWS CLI to display the public IP address of your instance.

$ aws ec2 describe-instances --instance-ids i-0c9c9b44b --query 'Reservations[*].Instances[*].PublicIpAddress' --output text

You can also display Public IP address of the instance where you have currently SSH'ed, using the following command in your putty terminal:

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

You can also display other metadata of your running instance where you have SSH'ed. 

Use the following command with the respective attribute(mentioned below) to display its respective value:

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

ami-id

ami-launch-index

ami-manifest-path

block-device-mapping/

events/

hostname

iam/

instance-action

instance-id

instance-type

local-hostname

local-ipv4

mac

metrics/

network/

placement/

profile

public-hostname

public-ipv4

public-keys/

reservation-id

security-groups

services/

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...