LoginSignup
1
1

More than 5 years have passed since last update.

EC2インスタンスにtagで付けた名前をサーバー内から取得する(勝手改定版)

Posted at

EC2インスタンスにtagで付けた名前をサーバー内から取得するという記事がやや情報古いので
最近の環境で同じことする。

$ aws ec2 describe-instances | jq -r '.Reservations[].Instances[] | {InstanceId, Name: (.Tags[] | select(.Key=="Name").Value)} | select(.InstanceId==$me_id) | .Name' --arg me_id `curl -s http://169.254.169.254/latest/meta-data/instance-id` | tr -d '\n'
my-web-server
  • aws-cliのインターフェース変更に対応
  • aws-cliをJSONで扱うことが多いのでパースを変更。jq使用。
1
1
1

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
1
1