LoginSignup
5
5

More than 5 years have passed since last update.

EC2のインスタンスIDを中から取得する

Posted at

169.254.169.254

169.254.169.254 というリンクローカルアドレスにアクセスすると様々なそのインスタンスに関連する情報が取得できる.このアドレスはホストOS側が管理していると思われるので,仮にDocker等を使ってさらに仮想化した場合も参照できる.

$ curl --fail http://169.254.169.254/latest/meta-data/instance-id
i-364653c4

スポットインスタンスの終了時刻

多くのアドレスは常に存在するがスポットインスタンスの終了時刻を返してくれる URL は必要な時にしか存在しない.

終了時刻が決定している時:

$ curl --fail http://169.254.169.254/latest/meta-data/spot/termination-time
2015-01-28T15:41:19Z

終了する予定が今のところない時:

$ curl --fail http://169.254.169.254/latest/meta-data/spot/termination-time
curl: (22) The requested URL returned error: 404 Not Found

その他

その他の詳しい情報は
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5