gpt4 book ai didi

amazon-web-services - 如何仅列出给定 CloudFormation 堆栈中的 EC2 实例?

转载 作者:行者123 更新时间:2023-12-04 00:33:41 24 4
gpt4 key购买 nike

我可以在下面的命令中使用什么来满足以下条件的 $QUERY:

aws ec2 describe-instances --query $QUERY
  1. 仅打印 aws:cloudformation:stack-name 标记等于 test-stack 的实例。
  2. 仅打印每个实例的 InstanceId 属性。
  3. 不诉诸管道、for 循环或其他 shell 花哨的东西。

最佳答案

这里需要使用一些参数:

查询

--query ( docs ) 仅检索 InstanceId

按堆栈名称标签过滤

--filter ( docs ) 用于排除未用堆栈名称标记的实例

  • tag-key - The key of a tag assigned to the resource. This filter is independent of the tag-value filter. For example, if you use both the filter "tag-key=Purpose" and the filter "tag-value=X", you get any resources assigned both the tag key Purpose (regardless of what the tag's value is), and the tag value X (regardless of what the tag's key is). If you want to list only resources where Purpose is X, see the tag :key =value filter.

  • tag-value - The value of a tag assigned to the resource. This filter is independent of the tag-key filter.

格式

--output ( docs ) 仅返回您查询的值(因此没有引号或 json/table 绒毛)

The text format organizes the AWS CLI's output into tab-delimited lines. It works well with traditional Unix text tools such as grep, sed, and awk, as well as Windows PowerShell.

像这样使用这些参数:

aws ec2 describe-instances \                                                     
--query "Reservations[*].Instances[*].InstanceId[]" \
--filters "Name=tag-key,Values=aws:cloudformation:stack-name" "Name=tag-value,Values=test-stack" \
--output=text

返回:

i-sd64f52a  i-das5d64a  i-sad56d4

关于amazon-web-services - 如何仅列出给定 CloudFormation 堆栈中的 EC2 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26707073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com