How can I get list of only running instances when using ec2-describe-tags
. I am using my command like this:
ec2-describe-tags --filter "resource-type=instance" --filter "value=somevalue" --filter "key=key"
Go to the instances section and click on "instances". It will show you all the running instances in the select region.
01 Sign in to the AWS Management Console. 02 Navigate to EC2 dashboard at https://console.aws.amazon.com/ec2/. 03 In the navigation panel, under INSTANCES section, choose Instances. 04 Select the underused EC2 instance that you want to resize (see Audit section part I to identify the right resource).
You can use the AWS Command Line Interface (AWS CLI) to launch, list, and terminate Amazon Elastic Compute Cloud (Amazon EC2) instances.
It is easy using the aws-cli:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --filters Name=instance-state-name,Values=running --output text
Expanding on John Rotenstein's answer you can definitely do this with describe-instances.
This will list Name tag and IP of all running instances whose Name tag contains a specific word:
name_tag=mongodb aws ec2 describe-instances --filter "Name=tag-key,Values=Name" "Name=tag-value,Values=*$name_tag*" "Name=instance-state-name,Values=running" --query "Reservations[*].Instances[*][Tags[?Key=='Name'].Value[],NetworkInterfaces[0].PrivateIpAddresses[0].PrivateIpAddress]" --output text
Output:
10.100.2.10 mongodb0 10.100.2.11 mongodb1 10.100.2.12 mongodb2
A bonus here is that leaving name_tag empty lists all running instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With