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

0 votes

Currently i use the following command to get all instance id's from my stack in json format:

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. I need the instances in the output sorted by the Hostrecord (Route53::RecordSet) or by the Logical ID in ascending order. For example: I have three instances with Hostrecord project1-avad.name.com, project2-avad.name.com, project3-avad.name.com. I want to get the instance id from project1 first, etc.

Unfortunately the documentation of describe-instances does not show a way to sort the output.

My Question:

Is it even possible to sort the output the way I want? If yes, where can I find the required documentation?

Sep 20, 2018 in AWS by bug_seeker
• 15,350 points
505 views

1 answer to this question.

0 votes

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.

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.

answered Sep 20, 2018 by Priyaj
• 56,900 points

Related Questions In AWS

0 votes
1 answer

AWS:Using S3 with EC2 instances

Yes, it can be used for instances ...READ MORE

answered Jun 26, 2018 in AWS by hemant
• 5,750 points
139 views
0 votes
1 answer
0 votes
1 answer

How to add SSL certificate to AWS EC2 with the help of new AWS Certificate Manager service

refer this link  https://aws.amazon.com/certificate-manager/faqs/ You can't install the certificates ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 56,900 points
79 views
0 votes
1 answer

Error when tried to invoke lambda function by AWS CLI

It looks like you need to provide ...READ MORE

answered Sep 10, 2018 in AWS by Archana
• 4,090 points
484 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

AWS EC2 Free Tier- how many instances can i run?

Amazon has a handy page that details ...READ MORE

answered Jul 6, 2018 in AWS by Priyaj
• 56,900 points
394 views