本文介绍了如何使用AWS CLI在Amazon EC2自动扩展组中使用特定标签获取实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用AWS CLI在自动扩展组中获取具有某些特定标签(例如environmentservice)的所有Amazon EC2实例.

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 .

到目前为止,我仅包含一个标签.如何同时包含标签和我需要ID的完整信息,例如可用性"区域,启动配置,实例,名称等.

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.

我该怎么做?

我正在使用以下查询:

 aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[? Tags[? (Key=='Environment') && Value=='staging']]".AutoScalingGroupName

推荐答案

可以从Auto Scaling组(使用与您上面提供的命令类似的命令)获得所需的某些信息(例如,启动配置).的信息与在自动伸缩组中启动的实例(例如,可用区)

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).

这是一条命令,它将返回有关特定Amazon EC2自动扩展组(例如my-autoscaling-group)中的实例的信息:

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

这篇关于如何使用AWS CLI在Amazon EC2自动扩展组中使用特定标签获取实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 05:33