Azure Function调用已安装包dbt时出现权限拒绝问题
Azure Function部署dbt后权限错误排查求助
问题概述
尝试创建Azure Function运行dbt(data build tool),本地运行正常,但部署后出现权限错误无法工作。
环境配置
- 操作系统:Linux
- 发布方式:代码(非Docker),此方式是否存在问题?
- 计划:Functions Premium EP1
- Python版本:3.9
- requirements.txt中已添加
dbt-core==1.3.0 - 测试方式:通过Azure门户的Function 'Code + Test'进行测试
测试目标
仅希望dbt帮助文本能显示在logging.info输出中,以此验证dbt是否可被调用。
函数代码(init.py)
import logging import subprocess import azure.functions as func def main(req: func.HttpRequest) -> func.HttpResponse: logging.info('Python HTTP trigger function processed a request.') logging.info('Start With Popen dbt') #with subprocess.Popen(["ls"], stdout=subprocess.PIPE, shell=True) as proc: # this runs fine, although shell cmd shell=True with subprocess.Popen(["/tmp", "dbt"], stdout=subprocess.PIPE) as proc: # Attempt to output dbt helper as doesn't write to log- When running locally subprocess.Popen(["dbt"] remove "/tmp" for line in proc.stdout: line = line.decode('utf-8').replace('\n', '').strip() logging.info(line) logging.info('End With Popen dbt')
错误信息
Result: Failure Exception: PermissionError: [Errno 13] Permission denied:'/tmp' Stack: File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 458, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py", line 701, in _run_sync_func return ExtensionManager.get_sync_invocation_wrapper(context, File "/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/extension.py", line 215, in _raw_invocation_wrapper result = function(**args) File "/home/site/wwwroot/HttpTrigger_dbt/__init__.py", line 11, in main with subprocess.Popen(["/tmp", "dbt"], stdout=subprocess.PIPE) as proc: # Attempt to output dbt helper as doesn't write to log- When running locally remove subprocess.Popen(["dbt"] remove "/tmp" File "/usr/local/lib/python3.9/subprocess.py", line 951, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "/usr/local/lib/python3.9/subprocess.py", line 1821, in _execute_child raise child_exception_type(errno_num, err_msg, err_filename)
排查情况
- 在
__init__.py中运行ls命令可正常工作,但这是shell命令而非调用已安装包的功能。 - 尝试设置
WEBSITE_RUN_FROM_PACKAGE = 0(参考微软问答帖子建议),但设置后无法重新部署,当前已确认该配置未被设置。 - 不确定问题所在,可能的情况:
- 无法在Azure Function中通过调用已安装包的方式运行dbt;
- 配置/设置存在遗漏;
WEBSITE_RUN_FROM_PACKAGE = 0本应生效,但存在独立的部署问题;- 需要以Docker而非代码方式发布?
更新排查信息
- 在
Azure Portal > Function App > Development Tools > SSH中运行pip list未找到dbt,仅显示pip、ptvsd等基础包。 - 运行
find -name "*dbt*"找到相关文件位于./site/wwwroot/.python_packages路径下,但直接运行dbt提示命令未找到; - 手动执行
pip install dbt-core后,dbt可正常输出帮助文本,此时dbt安装在/usr/local/bin路径下。
恳请提供相关帮助或建议。
内容的提问来源于stack exchange,提问作者marko0o
相关产品推荐
相关产品推荐

