问题
I am trying to get all the Amazon EC2 instances with some specific tags like environment
and service
in auto scaling group using the AWS CLI .
As of now I included only one tag. How can I include both the tags and I need the full information of ID like Availability zone, launch configuration, instances, name, etc.
How can I do that?
I am using query like:
aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[? Tags[? (Key=='Environment') && Value=='staging']]".AutoScalingGroupName
回答1:
Some of the information you seek (eg Launch Configuration) can be obtained from the Auto Scaling Group (using a command similar to what you provided above), while some of the information relates to the instances that are launched within the auto scaling group (eg Availability Zone).
Here is a command that will return information about instances in a specific Amazon EC2 auto scaling group (eg my-autoscaling-group
):
aws ec2 describe-instances --filter Name=tag:aws:autoscaling:groupName,Values=my-autoscaling-group --query "Reservations[*].Instances[*].[InstanceId,Placement.AvailabilityZone,Tags[?Key=='Name']|[0].Value]"
来源:https://stackoverflow.com/questions/57158470/how-to-get-the-instances-in-the-amazon-ec2-autoscaling-group-with-specific-tags