11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC2サーバー内から、インスタンス情報を参照する

Last updated at Posted at 2012-09-05
  • ログインしているインスタンスの情報をコマンドで取得する
  • root 不要
  • AWSの管理画面に入れてもらえないIT傭兵のために

○ 公式ドキュメントはこちら。
AWS documentation | Instance Metadata

どうやら、AWSのネットワーク内から参照できるAPIがあるようです。
WebAPIになっているので、curlで叩くと結果が帰ってきます。

詳細はドキュメントを参照すれば良いとして、汎用性の高そうな物をメモ。

インスタンスタイプ、その他

$ curl http://169.254.169.254/latest/dynamic/instance-identity/document/

{
  "kernelId" : "aki-XXXXXX",
  "ramdiskId" : null,
  "instanceId" : "i-XXXXXX",
  "instanceType" : "t1.micro",
  "billingProducts" : null,
  "architecture" : "x86_64",
  "version" : "2010-08-31",
  "accountId" : "XXXXXXXXXX",
  "imageId" : "ami-XXXXXXX",
  "pendingTime" : "2012-07-03T06:40:56Z",
  "availabilityZone" : "ap-northeast-1a",
  "devpayProductCodes" : null,
  "privateIp" : "xxx.xxx.xxx.xxx",
  "region" : "ap-northeast-1"
}

public-hostname

$ curl http://169.254.169.254/latest/meta-data/public-hostname
ec2-xxx-xx-xx-xx.ap-northeast-1.compute.amazonaws.com

public-ipv4

$ curl http://169.254.169.254/latest/meta-data/public-ipv4
xxx.xxx.xxx.xxx

security-groups

$ curl http://169.254.169.254/latest/meta-data/security-groups
mySecurtyGroups

セキュリティグループの細かい設定が見れないのが残念。。。

ついでに

AmazonLinuxOS のバージョン

$ cat /etc/system-release
Amazon Linux AMI release 2012.03
11
8
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
11
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?