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"
...
関数名を限定したい場合 find
と grep
と jq
で
$ find . -name "function.json" | grep Timer | xargs jq .bindings[].schedule
"0 */5 * * * *"