grep your EC2 Instances in a Region Using the CLI

Assuming you have the AWS CLI installed, you can easily grep instances in a Region. To see your Default region name, type aws configure and hit Enter twice.

To allow grep to work nicely with the output, enter “text” for the Default output format

aws configure
AWS Access Key ID [*******************]:
AWS Secret Access Key [*******************]:
Default region name [us-west-1]: 
Default output format [text]: text

In this example, we’ll show basic instance information such as the name of the Reservation, the State and the StateReason. We’ll use grep’s OR operator.

aws ec2 describe-instances | grep 'RESERVATION\|STATE\|STATEREASON'

The CLI will respond with something like the following:

RESERVATIONS 123222575111 r-0c1xbac1122y90121
STATE 80 stopped
STATEREASON Client.UserInitiatedShutdown 
Client.UserInitiatedShutdown: User initiated shutdown
...

At a glance, you can easily inspect all the EC2 instances in your Region.

Feature Photo by Hendrik Morkel on Unsplash