首页 > 解决方案 > 在 Python Azure 函数中访问绑定表达式值

问题描述

是否可以function.json从 Python Azure 函数中访问绑定表达式的值?

这就是我想要做的:

function.json

{
    "scriptFile": "__init__.py",
    "disabled": false,
    "bindings": [
        {
            "name": "myblob",
            "type": "blobTrigger",
            "direction": "in",
            "path": "samples-workitems/{folder1}/{folder2}/",
            "connection":"MyStorageAccountAppSetting"
        }
    ]
}

__init__.py

import logging
import azure.functions as func


def main(myblob: func.InputStream):
    logging.info('Python blob folder 1: %s', myblob.folder1)
    logging.info('Python blob folder 2: %s', myblob.folder2)

这个示例使它看起来应该可以工作,但实际上name变量似乎是硬编码的。

标签: pythonazureazure-functionsazure-blob-storage

解决方案


要将函数的返回值用作输出绑定的值,绑定的name属性应设置为$returnin function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "req",
      "direction": "in",
      "type": "httpTrigger",
      "authLevel": "anonymous"
    },
    {
      "name": "msg",
      "direction": "out",
      "type": "queue",
      "queueName": "outqueue",
      "connection": "AzureWebJobsStorage"
    },
    {
      "name": "$return",
      "direction": "out",
      "type": "http"
    }
  ]
}

有关更多信息,请检查绑定表达式


推荐阅读