AWS Cli – Search EC2 instances by tag and state

 

To get the IP addresses of all instances with the “Application” tag and its value “Frontend“, and also filter by state to display information about only those instances that are in the “running” state:

aws ec2 describe-instances --filter "Name=tag:Application,Values=Frontent" "Name=instance-state-name,Values=running" --query "Reservations[*].Instances[*][NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress]" --output text

 

To display the name of instance along with the IP address:

aws ec2 describe-instances --filter "Name=tag:Application,Values=Frontend" "Name=instance-state-name,Values=running" --query "Reservations[*].Instances[*][Tags[?Key=='Name'].Value[],NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress]" --output text

Tagged: Tags

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments