25
23

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インスタンスにtagで付けた名前をサーバー内から取得する

Posted at

EC2起動時にName=my-web-serverというtagを付けたとき、
立ち上げたサーバー内からこのタグを取得する方法。

[ec2-user@ip-10-150-000-00 ~]$ ec2-describe-instances | grep `/usr/bin/curl -s http://169.254.169.254/latest/meta-data/instance-id` | grep TAG | grep Name | cu
t -f5
my-web-server

EC2インスタンスから169.254.169.254(全region共通らしい)にHTTPリクエストを送ることで、自身のメタデータをREST的に取得することが出来る。

自身のinstance-id, TAG行, keyがNameのもの、とgrep絞り込んでcutする。
grepの積集合マッチ、正規表現でもっと簡単に書けそう...。

25
23
2

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
25
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?