How to get the instance id from within an ec2 inst

2019-01-01 16:27发布

How can I find out the instance id of an ec2 instance from within the ec2 instance?

27条回答
人间绝色
2楼-- · 2019-01-01 17:21

Run this:

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

You will be able to see different types of attributes which are provided by aws.

Use this link to view more

查看更多
萌妹纸的霸气范
3楼-- · 2019-01-01 17:23

For .NET People :

string instanceId = new StreamReader(
      HttpWebRequest.Create("http://169.254.169.254/latest/meta-data/instance-id")
      .GetResponse().GetResponseStream())
    .ReadToEnd();
查看更多
大哥的爱人
4楼-- · 2019-01-01 17:24

A more contemporary solution.

From Amazon Linux the ec2-metadata command is already installed.

From the terminal

ec2-metadata -help

Will give you the available options

ec2-metadata -i

will return

instance-id: yourid
查看更多
登录 后发表回答