I have this bash script that is trying to return the stopped instance Ids of an autoscaling group.
aws ec2 describe-instances --filter "Name=tag:aws:autoscaling:groupName,Values=devASG-123" --query "Reservations[].Instances[?State.Name==stopped].InstanceId" --output text --profile dev
This keeps returning a blank value even though I have instances that are stopped
How can i fix this?
CodePudding user response:
Try this:
aws --profile dev ec2 describe-instances --filters \
"Name=tag:aws:autoscaling:groupName,Values=devASG-123" \
"Name=instance-state-name,Values=stopped" \
--query "Reservations[*].Instances[*].InstanceId
or use regex
aws --profile dev ec2 describe-instances --filters \
"Name=tag:aws:autoscaling:groupName,Values=devASG-123" \
"Name=instance-state-name,Values=stopped" | \
grep -o '\"i-[0-9a-f]\\ \"' | grep -o '[^\"]\\ '