[PYTHON] Can be used when aws-cli is available but jq is not available jp.py

Introduction

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.

About JMESPath and jp.py

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.

How to use

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.

Bad points of jp.py

Gugu's ability is too low. .. .. ..

reference

The following was very helpful. Thank you very much.

[Personal memo] Let's use jmespath for JSON parsing Can be used with aws-cli – use query = jmespath tightly Four snippets that take advantage of the enhanced query options in AWS CLI 1.3 for Python

Recommended Posts

Can be used when aws-cli is available but jq is not available jp.py
python note: when easy_install is not available
One solution when numpy can be entered via pip but not via poetry
If "can not be used when making a PIE object" appears in make
pd.tseries.offsets.DateOffset can be quite slow if not used with caution
[Python] Variadic arguments can be used when unpacking iterable elements
Scripts that can be used when using bottle in Python
When I try to use pip, SSL module is not available.