0

I am trying to run the ec2 describe-instances command and output as table sorted by PrivateIPAddress.

I tried this command.

aws ec2 describe-instances \
  --instance-id $instances 
  --region us-west-2 
  --output table 
  --query 'Reservations[].Instances[].{LaunchTime:LaunchTime,InstanceId:InstanceId,PrivateIpAddress:PrivateIpAddress,Name:Tags[?Key==`Name`] | [0].Value, Status:State.Name} | sort_by(@, &[2])'

It fails with this error

In function sort_by(), invalid type for value: {'LaunchTime': '2023-05-04T08:10:46+00:00', 'InstanceId': 'i-23424242424234234aef', 'PrivateIpAddress': 'xx.xxx'.xx.xxx, 'Name': 'sdkjsdfk', 'Status': 'running'}, expected one of: ['string', 'number'], received: "null"

What am I doing wrong?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
thej
  • 19
  • 2
  • See @TrevorW's answer on [sort output of describe-instances?](https://stackoverflow.com/a/55908861/174777) -- it involves enclosing the entire expression in a `sort_by`. – John Rotenstein May 11 '23 at 08:48
  • That worked. had come across it and tried a few things on that page but not the one suggested by @TrevorW – thej May 12 '23 at 05:57

0 Answers0