Yaroslav Bulatov
Yaroslav Bulatov

Reputation: 57923

How to find out name of current instance from command-line?

Is there an easy way to determine (ie, through boto3 or aws-cli), which instance I'm on, from an SSH session in that instance?

Upvotes: 3

Views: 1166

Answers (1)

helloV
helloV

Reputation: 52393

When you say which instance, do you mean the instance id or instance name or instance private ip or instance public ip?

Query the instance metadata server.

curl 169.254.169.254/latest/meta-data/instance-id

If you want the instance tags:

aws ec2 describe-tags --filters "Name=resource-id,Values=instance_id"

or

aws ec2 describe-tags --filters "Name=resource-id,Values=`curl
169.254.169.254/latest/meta-data/instance-id`"

For instance's private IP:

curl 169.254.169.254/latest/meta-data/local-ipv4

For all available values:

curl 169.254.169.254/latest/meta-data/

Upvotes: 4

Related Questions