はじめに
TimerTriggerをローカルで動かそうかなと思っていたらこんなエラーがでました。
Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger, orchestrationTrigger, activityTrigger, entityTrigger. You can run 'func azure functionapp fetch-app-settings <functionAppName>' or specify a connection string in local.settings.json.
functionsがAzureにある場合はlocal.settings.jsonをfetch-app-settingsを使って取得することでAzureWebJobsStorageの情報が設定されます。
ローカルで動かしている段階では大抵Azureにリソースはないと思います。
解決策
azuriteをインストールします。
npm install -g azurite
azuriteを起動します
$ azurite --silent --location /products/azurite --debug /products/azurite/debug.log
Azurite Blob service is starting at http://127.0.0.1:10000
Azurite Blob service is successfully listening at http://127.0.0.1:10000
Azurite Queue service is starting at http://127.0.0.1:10001
Azurite Queue service is successfully listening at http://127.0.0.1:10001
Azurite Table service is starting at http://127.0.0.1:10002
Azurite Table service is successfully listening at http://127.0.0.1:10002
BlobService,QueueService,TableServiceがそれぞれのポートで起動します。
あとはlocal.settings.jsonでazuriteを見るように修正します
local.settings.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "node",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
functionsをローカルで起動します。
$ func start
Azure Functions Core Tools
Core Tools Version: 3.0.3442 Commit hash: 6bfab24b2743f8421475d996402c398d2fe4a9e0 (64-bit)
Function Runtime Version: 3.0.15417.0
Functions:
export: timerTrigger
For detailed output, run func with --verbose flag.
[2021-05-18T02:40:04.799Z] Worker process started and initialized.
[2021-05-18T02:40:10.063Z] Host lock lease acquired by instance ID '0000000000000000000000005FB90853'.
[2021-05-18T02:45:00.072Z] Executing 'Functions.export' (Reason='Timer fired at 2021-05-18T11:45:00.0412924+09:00', Id=ff122567-13fe-46e8-81e0-948ac19ff6e0)
[2021-05-18T02:45:00.152Z] Timer trigger function ran! 2021-05-18T02:45:00.141Z
[2021-05-18T02:45:00.190Z] Executed 'Functions.export' (Succeeded, Id=ff122567-13fe-46e8-81e0-948ac19ff6e0, Duration=141ms)