How to get the instances in the Amazon EC2 autoscaling group with specific tags using AWS CLI?

天涯浪子 提交于 2019-12-12 07:04:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!