In rare cases, there is an environment where jq cannot be used even though there is aws-cli. It is reasonable to point out that jq should be included, but that may not be the case, so I will explain jp.py that can be used in such cases.
I learned from the text of JAWSUG CLI Branch.
The python implementation of the query language JMESPath for JSON is jp.py. JMESPath is also available in the aws-cli query option. I am happy that jp.py is installed together with aws-cli and can be executed with a single command. You can also refer to Tutorial for JMESPath. The purpose is the same as jq, but the language is different.
Get the instance ID with jp.py from the instance list obtained with aws-cli.
$ aws --region ap-northeast-1 ec2 describe-instances | jp.py 'Reservations.Instances.InstanceId' [ "i-297dXXXX", "i-c0e2XXXX", "i-02965fbeXXXXXXX" ]
jp.py --help As you can see, it's simple.
$ jp.py --help usage: jp.py [-h] [-f FILENAME] [--ast] expression positional arguments: expression optional arguments: -h, --help show this help message and exit -f FILENAME, --filename FILENAME The filename containing the input data. If a filename is not given then data is read from stdin. --ast Pretty print the AST, do not search the data.
Gugu's ability is too low. .. .. ..
The following was very helpful. Thank you very much.