简体   繁体   English

按Hostrecord(Route53 :: RecordSet)对aws-cli ec2 describe-instances的输出进行排序

[英]Sort output of aws-cli ec2 describe-instances by Hostrecord (Route53::RecordSet)

Currently i use the following command to get all instance id's from my stack in json format: 目前,我使用以下命令以json格式从堆栈中获取所有实例ID:

aws ec2 describe-instances --query Reservations[*].Instances[*].InstanceId[] --filters Name=tag-key,Values=aws:cloudformation:stack-name Name=tag-value,Values=Stack-Name-XYZ --output=json

This command works fine but returns the instance id's in a different order which I need to change. 该命令可以正常工作,但是以我需要更改的其他顺序返回实例ID。 I need the instances in the output sorted by the Hostrecord (Route53::RecordSet) or by the Logical ID in ascending order. 我需要按Hostrecord(Route53 :: RecordSet)或按逻辑ID升序排序的输出中的实例。 For example: I have three instances with Hostrecord project1-avad.name.com, project2-avad.name.com, project3-avad.name.com . 例如:我有三个实例,分别是Hostrecord project1-avad.name.com, project2-avad.name.com, project3-avad.name.com I want to get the instance id from project1 first, etc. 我想先从project1获取实例ID,依此类推。

Unfortunately the documentation of describe-instances does not show a way to sort the output. 不幸的是, describe-instances的文档没有显示对输出进行排序的方法。

My Question: 我的问题:

Is it even possible to sort the output the way I want? 甚至可以按照我想要的方式对输出进行排序吗? If yes, where can I find the required documentation? 如果是,我在哪里可以找到所需的文档?

The easiest way I can think of doing this is by piping it through python, ruby or some other scripting language that can parse your JSON and output it as desired. 我想到的最简单的方法是通过python,ruby或其他可以解析JSON并根据需要输出的脚本语言将其管道化。

Alternately, if you're performing actions to multiple instances at once and this is not a once-off change, you should probably be looking into an orchestration framework like AWS CloudFormation or Hashicorp's excellent Terraform in order to manage this via a DSL rather than through hand-built scripting. 或者,如果您要一次对多个实例执行操作,而这并不是一次更改,那么您可能应该考虑使用诸如AWS CloudFormationHashicorp出色的Terraform之类的编排框架,以便通过DSL(而不是通过DSL)进行管理手工构建的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM