AWS CLI command to list stopped instances

Viewed 4381
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?

2 Answers

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[]'

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"
Related