AmazonEC2ReadOnlyAccessをIAMロールにつけてアタッチし、以下を実行
1 |
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/' |
参考