如何访问Azure函数输入绑定中的EventGrid触发器事件属性

2024-06-01 11:54:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我想根据触发的eventgrid事件的内容(python worker运行时)将cosmos文档拉入azure函数中。有可能这样做吗

我有以下function.json:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    },
    {
      "name": "documents",
      "type": "cosmosDB",
      "databaseName": "Metadata",
      "collectionName": "DataElementMappings",
      "sqlQuery" : "SELECT * from c where c.id = {subject}",
      "connectionStringSetting": "MyCosmosDBConnectionString",
      "direction": "in"
  }
  ]
}

我想在cosmos输入绑定的查询中使用事件的属性。我试过这个主题。它失败于:

[6/4/2020 5:34:45 PM]System.Private.CoreLib:执行函数时出现异常:Functions.orch_taskchecker。System.Private.CoreLib:字典中不存在给定的密钥“subject”

所以我没有使用正确的密钥名。我得到的唯一关键是{data},但不幸的是,我无法使用文档中所述的语法{data.property}访问事件数据中的任何属性。我希望所有事件网格模式键都可以在其他绑定中使用,因为事件是JSON负载。我没有让他们工作,例如事件时间、事件类型、主题等

因为我看到了一个存储队列的相同想法的示例,它们使用了例如{Queue.id},所以我尝试了类似{Event.subject}、{EventGridEvent.subject}的方法,但都没有效果

在文档中,我找不到其他绑定中使用的事件网格触发器数据的示例。这能实现吗


Tags: 函数namein文档id主题属性type
2条回答

有一个event.get_json()方法可以用来访问python代码中的数据字段,我没有查看绑定

对于EventGridTriggerC#script)可以用于输入绑定EventGridEvent类的自定义数据对象

以下示例显示事件存储帐户的blob输入绑定:

 {
    "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "eventGridEvent",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "body",
      "path": "{data.url}",
      "connection": "rk2018ebstg_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

请注意,只能引用数据对象中的属性

相关问题 更多 >