AWSCLi Get Instances from List

This script is designed to run line by line of a text file containing EC2 Instance ID’s. I then Queried the results to only show the ID, Name and State (other properties can be added with ease). I also decided output to text was best for the results to be in human readable format.

NOTE – If you do not use multiple profiles then you can remove the $profile variable and the switch. Also remove the echo line and read line.

#/bin/sh
# Ben Prudence - Get Inbstances from Text File of Instance IDs

echo -n "Profile Name: "
read profile
cat InstanceList.txt | while read instance
do
 aws ec2 describe-instances --instance-ids $instance --profile $profile --query 'Reservations[].Instances[].[InstanceId, Tags[?Key==`Name`] | [0].Value, State.Name]' --output text
done

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.