List Instance Having Particular Tags Using AWS CLI

AWS CLI Command To List Instance Having Particular Tag

Command To list AWS Instances With Particular Tag

AWS CLI is a command line utility to play with AWS resources. AWS CLI allows to list instances on the basis of various filters. To install aws-cli, here is a tutorial to install and configure aws-cli.

Following is the command to list only instance-id of all the instances having a Tag “Monitor” with value “True”.

aws ec2 describe-instances --filters Name=tag:Monitor,Values=True --query 
'Reservations[].Instances[].[InstanceId]' --output text

Here we are only listing the Instance-Id, you may also get other details like Private IP address as shown below:

aws ec2 describe-instances --filters Name=tag:Monitor,Values=True --query 
'Reservations[].Instances[].[InstanceId,PrivateIpAddress]' --output text

We have also specified output to be in text format, which will display two columnar data, one column for InstanceId and other for PrivateIpAddress. If you don’t want columnar type output want the output then just remove the “–output text” from the command:

aws ec2 describe-instances --filters Name=tag:Monitor,Values=True --query 
'Reservations[].Instances[].[InstanceId,PrivateIpAddress]'

Leave a Reply

Your email address will not be published. Required fields are marked *