Reputation: 57923
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
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