株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

AmazonEC2ReadOnlyAccessをIAMロールにつけてアタッチし、以下を実行

sudo aws ec2 describe-instances --region $(sudo curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region') --instance-id $(sudo curl -s http://169.254.169.254/latest/meta-data/instance-id) | jq '.Reservations[].Instances[] | {Value: (.Tags[] | select(.Key=="Name").Value)}' | grep [0-9a-zA-Z] | sed 's/^.*"\(.*\)".*$/\1/'

参考

【AWS CLI】1行でEC2に自身のNameタグを取得させる

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)