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,510 points
3,334 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
• 58,020 points

Related Questions In AWS

0 votes
1 answer

How to find exact stopped time of AWS EC2 instances?

Hi@Lakshminarayanan, You can use InstanceState Data Types in your ...READ MORE

answered Dec 3, 2020 in AWS by MD
• 95,460 points
3,392 views
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,790 points
6,349 views
0 votes
1 answer
+1 vote
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
• 58,020 points
1,879 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
• 58,020 points
3,103 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP