如果我想在我的nodejs函数中调用Linux可执行库,Azure函数: do I have to use Premium plan's custom linux image feature,?

标签 azure azure-functions

我是 Azure 新手,所以如果这是显而易见的,请原谅。

我正在构建一个 Azure Linux Nodejs 函数,该函数将 zip 文件从 Blob 存储下载到本地文件系统,解压缩该文件,并使用名为 GDCM 的 Linux 库从解压缩的 中提取信息.dicom 文件,最后将解压后的文件上传回 Blob 存储。

在 AWS Lambda 中,我可以通过为 lambda 函数创建一个层来很好地做到这一点:

When you create a layer, you must bundle all content files of the library into a .zip file archive. You upload the .zip file archive to your layer from Amazon Simple Storage Service (Amazon S3) or your local machine. Lambda extracts the layer contents into the /opt directory when setting up the execution environment for the function.

为了实现相同的目标,我是否需要构建包含 GDCM Linux 库的自定义 Linux 镜像?这意味着我必须使用高级计划。

或者我可以通过使用消费计划来达到同样的目标吗?

最佳答案

发布我的评论作为社区的答案。

  • 您的函数应用项目文件可以使用 Azure Functions 的 zip 部署功能从 a.zip(压缩)上传到 Azure。此外,您可以立即从部署包文件执行您的函数。此方法省略了将文件从包移动到函数应用的 wwwroot 目录的部署阶段。相反,Functions 运行时会挂载包文件,使 wwwroot 目录的内容变为只读。然后在您的 Function 应用配置中添加 WEBSITE_RUN_FROM_PACKAGE- 1 设置。此设置将从压缩包中执行您的函数。

  • 利用您喜欢的工具,您可以为您的项目创建 .zip 包并将其上传到 Azure 中的函数应用。可以使用 Azure CLI 启动推送部署。命令

az functionapp deployment source config-zip -g <resource_group> -n \
<app_name> --src <zip_file_path>

enter image description here

引用此document用于 Azure 函数的 zip 部署。

关于 GDCM 库,您可以上传 .zip 包,其中包含函数应用中包含的库文件。配置函数执行环境时,库文件会被解压到/opt目录下。

您可以按照以下步骤操作-

在函数应用的项目根目录中,创建一个名为 bin 的文件夹。

您可以通过在 Kudu 控制台中创建函数应用来访问函数应用的根目录:-

enter image description here

将 GDCM 库文件复制到 bin 文件夹。将以下行添加到 function.json 文件中,将 libgdcm.so 替换为 GDCM 库文件的名称,如下所示:-

function.json

{
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "res"
    }
  ],

"entryPoint": "MyNamespace.Function.Run",
"libraryPath": "/home/site/wwwroot/bin/libgdcm.so"

}

使用您选择的工具,为您的项目创建 .zip 包。应将 .zip 包上传到 Azure 中的函数应用。配置函数执行环境时,会解压库文件并放置在/opt目录下。

一种替代方法是对您的 Function 应用进行 docker 化,并在 Azure Function docker 文件中安装自定义 Linux 库并进行部署。

关于如果我想在我的nodejs函数中调用Linux可执行库,Azure函数: do I have to use Premium plan's custom linux image feature,?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76735675/

相关文章:

Azure Functions HttpClient 根据请求没有已知这样的主机

azure - 尽管值为 true,但阶段条件未评估为 true

azure - 通过 REST API 获取 iothub 注册设备

azure - 如何使用Azure Devops任务清理Azure数据工厂的工作区?

Azure 函数 host.json 以某种方式被忽略

azure - 使用 terraform 部署 Azure powershell 函数应用程序时出现问题

azure - Azure 函数中针对 Cosmos DB 的 SQL 注入(inject)

带有 Web API 的 Azure B2C

powershell - Azure PowerShell Set-AzureRmSqlDatabase 挂起/非常慢

Azure应用程序网关: HostName Mystery