LoginSignup
51
29

More than 5 years have passed since last update.

EC2インスタンス内から情報を取得する方法

Last updated at Posted at 2017-09-15

概要

AWS EC2のインスタンスIDやホスト名、AMI-IDなどの情報を、EC2インスタンス内から取得する方法を記載します。
169.254.169.254を叩くと色々と教えてくれるようです。

インスタンスIDを取得する

curlコマンドを使って取得できます。

$ curl 169.254.169.254/latest/meta-data/instance-id/
i-577f7355

取得可能な項目一覧

何が取れるかを知りたいときに

$ curl http://169.254.169.254/latest/meta-data/
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
hostname
instance-action
instance-id
instance-type
kernel-id
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups

グローバルIPアドレスを知りたいとき

EC2インスタンスに付与されている、IPv4アドレスを知りたい場合は、このコマンドで取得できます。

$ curl -q http://169.254.169.254/latest/meta-data/public-ipv4
xxx.xxx.xxx.xxx
51
29
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
51
29