Reputation: 961
ec2-describe-instances --filter "instance-state-name=stopped"
This helps me list all stopped instances with all its details. How should I modify the command that it only gives me the names of the stopped instances?
Upvotes: 6
Views: 6601
Reputation: 96
you can use aws cli combined with other tools like jq
aws ec2 describe-instances \
--filter Name=instance-state-name,Values=stopped \
--query 'Reservations[].Instances[].{ID: InstanceId,Hostname: PublicDnsName,Name: Tags[?Key==`Name`].Value }' \
| jq '.[] | .Name[]'
this will produce output in form:
"instance2"
"instance1"
Upvotes: 4
Reputation: 52393
You are using old style commands. Use AWS CLI
to get what you want.
aws ec2 describe-instances --filters "Name=instance-state-name,Values=stopped" --query 'Reservations[].Instances[].Tags[?Key==`Name`].Value[]'
Upvotes: 12