9
8

More than 5 years have passed since last update.

Amazon AWS 上でのホスト情報取得

Last updated at Posted at 2014-06-18

Amazon AWS 上で ELB+AutoScaling を利用している場合など、ホスト情報が頻繁に変わってしまうのでホスト情報を取得するためのスクリプトです。
aws コマンドを実行して running 状態のインスタンス情報を出力しているだけですが結構便利です。

Key Value
Name ホスト名

というタグが設定されている必要があります。

sh
region="--region ap-northeast-1"
output="--output text"
query="--query Reservations[*].Instances[*].[Tags[?Key==\`Name\`].Value,InstanceId,PublicIpAddress,PrivateIpAddress]"
filter="--filter Name=instance-state-name,Values=running"
aws="/usr/bin/aws ec2 describe-instances ${region} ${output} ${query} ${filter}"

${aws} | awk '{ if(NR % 2) ip = $0; else printf "%s     %s\n", $0, ip; }'
9
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
9
8