Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.
  • ログインしているインスタンスの情報をコマンドで取得する
  • 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
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away