LoginSignup
3
2

More than 3 years have passed since last update.

Tips: Azure Functions 複数の function.json の中身をずらっと jq する

Posted at

Intro

Azure Functions では、function.json にトリガーやバインディングなどの設定がされているが、数十といったレベルで多くの関数を作成したときに、この設定内容を一覧で確認したいことがある。function 名の一覧ならば、ソースコード上のディレクトリ名や Azure Portal 上で簡単に取得できるが、function.json の中身となると一つずつ開いて確認するのは効率が悪いので、find、xargs、jq などのコマンドラインで解決する。

Azure Cloud Shell でもよいし、Windows マシンでも WSL でこのあたりのコマンドラインがさらっと利用できるので、手軽に確認できる。

How

状況はこんな感じでたくさんの関数を作ったとする。

$ ls *
host.json  local.settings.json  requirements.txt 

BlobTrigger1:
function.json  __init__.py  readme.md  sample.dat

CosmosTrigger1:
function.json  __init__.py  sample.dat

HttpTrigger1:
function.json  __init__.py  sample.dat

TimerTrigger1:
function.json  __init__.py  readme.md  sample.dat

... まだまだたくさん

たまたま Python を使っているが、function.json は言語に関わらず利用する。JavaScript でも Java でも C# でも同じ方法が使える。

シンプルに jq

全てをずらっと

jq (query) (file path) なので

$ jq . ./*/function.json
... JSON結果は省略 ...

cat をパイプする派であれば

$ cat ./*/function.json | jq .
... JSON結果は省略 ...

bindings.type をずらっと

$ jq .bindings[0].type ./*/function.json
"blobTrigger"
"cosmosDBTrigger"
"httpTrigger"
"timerTrigger"
...

関数名を限定したい場合 findgrepjq

$ find . -name "function.json" | grep Timer | xargs jq .bindings[].schedule
"0 */5 * * * *"

Reference

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2