使用 local.settings.json 的 Azure 函数 cosmos db 输出

丹·柯克汉姆

查看有关 azure 函数的文档,特别是这个如何通过门户设置集成非常清楚,但在本地开发则非常模糊。

我的代码结构如下:

[FunctionName("foobar")]
public static void Run([QueueTrigger("foo")]Foo myQueueItem, out object dbFoo)
{
  //do cool stuff here
}

队列触发器与 Azure 存储模拟器配合得很好,但没有关于如何设置local.settings.json 的说明通过 Visual Studio 自动生成的文件如下所示:

{
   "IsEncrypted": false,
   "Values": {
      "AzureWebJobsStorage": "UseDevelopmentStorage=true",
      "AzureWebJobsDashboard": ""
   }
}

cosmos db 的连接信息在这个结构中的什么位置才能使函数正确运行?

米哈伊尔·希尔科夫

它应该是这样的:

public static void Run(
    [QueueTrigger("foo")] Foo myQueueItem, 
    [DocumentDB("MyDB", "MyCollection", ConnectionStringSetting = "MyConnectionString")]
    out object dbFoo)

配置将是:

{
    "IsEncrypted": false,
    "Values": {
        "MyConnectionString": "...your cosmos db string..."
    }
}

在 Azure 中,您必须将MyConnectionString参数放入应用程序设置。

更新:在 V2 版本的 FunctionsDocumentDB绑定属性被属性替换CosmosDB,请参阅文档

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

从Azure函数使用Cosmos DB表API

使用 JavaScript Azure 函数写入 Azure Cosmos DB

Azure 函数 - local.settings.json 与 launchSettings.json

Azure函数将local.settings.json读取为对象

Azure 函数 - Cosmos DB 删除文档问题

是否可以从函数内部使用变量动态调用Azure函数的Cosmos DB输入绑定的SQL查询?

使用遍历查询Azure Cosmos DB图形

使用Azure cosmos DB进行表达

在Azure函数中使用CosmosDbTrigger在Cosmos DB中检测更新和删除

如何使用 Azure 函数 Cosmos DB 触发器更新集合中的文档?

如何使用带有 TypeScript 的 Azure 函数更新 cosmos db 中子文档中的特定值

Azure存储队列-Cosmos DB输出-错误处理

Azure函数的Azure Cosmos DB输入绑定不起作用

从 azure 函数写入 azure cosmos db 不会创建任何实体

从Powershell脚本调用Azure Cosmos DB UDF函数

Azure Cosmos DB 更改源函数未触发

Azure 函数从 Cosmos Db Mongo 集合返回空数据集

通过azure函数更新和删除cosmos db中的文档

从 azure 函数有条件地插入 Cosmos DB

Azure函数,使local.settings.json值优先于系统环境变量

如何将local.settings.json从Azure函数移植到.NET核心Web项目?

建模Azure Cosmos DB

Azure Cosmos DB 分区

Azure Cosmos DB查询

如何使用Terraform输出Cosmos DB连接字符串

如何使用Azure Function App备份Azure Cosmos DB

Azure Cosmos DB-可以创建JSON文档的副本

如何在Azure Cosmos DB中深度搜索JSON?

如何将VS中存储在local.settings.json中的SignalRConnectionString上传到Azure门户上的Azure函数