如何让 cosmos db 触发 azure 函数并调用另一个 http 函数

How to have an azure function triggered by cosmosdb and call another http fuction

我需要监听 azure cosmos db 的变化,然后根据我收到的信息对另一个 api 进行 POST 调用。

我添加了这个function.json

{
  "bindings": [
    {
      "type": "cosmosDBTrigger",
      "name": "input",
      "direction": "in",
      "leaseCollectionName": "leases",
      "connectionStringSetting": "validAppsTrigger2_ConnectionString",
      "databaseName": "dev",
      "collectionName": "validApps",
      "createLeaseCollectionIfNotExists": true
    },
    {
      "name": "response",
      "direction": "out",
      "type": "http"
    }
  ]
}

这是我的 index.js

module.exports = function (context, input) {
    context.log('Document Id: ', input[0].id);
    // should I call http manually here?
    context.done();
};

但我不确定如何从那里调用另一个 azure http 函数,

Do I need an out binding at all?

否,HTTP 输出绑定需要 HTTP 触发器。您正在使用 Cosmos 触发器,所以这不能是 done.Ref:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-output.

Use the HTTP output binding to respond to the HTTP request sender. This binding requires an HTTP trigger and allows you to customize the response associated with the trigger's request.

Should I just make a regular http call in the above function?

是的,您可以像@Thiago Custodio 所说的那样在您的函数中进行常规的 http 调用。