エンジニア成長日記

成長するにはインプットばかりでなく、アウトプットも必要である。日々の成長記録を書き留めていきたい。

Azure Function を利用したプログラミング(Python)

Azure Function を利用したプログラミング(Python

Azure Function を利用したプログラミング中に発生したエラーの備忘録

〇現状

Azure Functions → ADLS Gen2の一覧を取得時に発生したエラー

2020-07-24T10:37:42.708 [Error] Executed 'Functions.TimerTrigger1' (Failed, Id=XXXXXXXXXXXXX)Result: FailureException: ModuleNotFoundError: No module named 'azure.storage'. Troubleshooting Guide: https://aka.ms/functions-modulenotfoundStack:   File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 255, in _handle__function_load_requestfunc = loader.load_function(File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 31, in callraise extend_exception_message(e, message)File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 29, in callreturn func(*args, **kwargs)File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 73, in load_functionmod = importlib.import_module(fullmodname)File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "/home/site/wwwroot/TimerTrigger1/__init__.py", line 7, in <module>from azure.storage.filedatalake import DataLakeServiceClient

〇原因

プログラム内で利用しているライブラリがない場合に発生するエラー。

〇対応

Pythonでは、「requirements.txt」というファイルに依存パッケージを記載することで読み込むことが可能である。

Azure Functionsでは、既定でリモート ビルド時に当該ファイルを参照し、依存パッケージを動的にダウンロードする。

※参考:Azure Functions の Python 開発者向けリファレンス | Microsoft Docs