'How can i retrieve the instance id of an instance that is part of an auto scaling group?
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?
Solution 1:[1]
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 '[^\"]\\+'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
