【发布时间】:2019-11-26 19:37:16
【问题描述】:
我正在开发一个 Azure 函数,每次在 CosmosDB 中更新文档时都会触发该函数。我已经成功完成了它,但现在我想避免在 CosmosDBTrigger 装饰器中硬编码值。
正如我在另一篇 SO 帖子中看到的那样,我已经尝试使用“%”符号来引用存储的应用程序值。但是,它似乎不起作用。帖子是:Is it possible to configure Azure C# function DocumentDB attribute arguments?
这是我正在尝试的解决方案:
public static void Run([CosmosDBTrigger(
databaseName: "%LogLevelsCachingDatabaseName%",
collectionName: "%LogLevelsCachingCollectionName%",
ConnectionStringSetting = "%LogLevelsCachingDatabaseSetting%",
LeaseCollectionName = "%LogLevelsCachingLeaseCollectionName%",
StartFromBeginning = true
)]IReadOnlyList<Document> input, ILogger log)
{
if (input == null || input.Count <= 0) return;
工作解决方案完全相同,但 '%' 之间的值是硬编码值。
这是我将 Azure 函数发布到 Azure DevOps 时的输出。请注意,ConnectionStringSetting 值是有效的,因为我已经能够运行 Azure 函数,而硬编码值没有任何问题。
错误:
函数 (CacheLogLevels) 错误:Microsoft.Azure.WebJobs.Host:错误索引方法“CacheLogLevels”。 Microsoft.Azure.WebJobs.Extensions.CosmosDB:无法使用数据库 %LogLevelsCachingDatabaseName% 中的租约 %LogLevelsCachingLeaseCollectionName% 为数据库 %LogLevelsCachingDatabaseName% 中的 %LogLevelsCachingCollectionName% 创建集合信息:无法解析属性“CosmosDBTriggerAttribute.ConnectionStringSetting”的应用程序设置。确保应用设置存在并且具有有效值。 Microsoft.Azure.WebJobs.Extensions.CosmosDB:无法解析属性“CosmosDBTriggerAttribute.ConnectionStringSetting”的应用设置。确保应用设置存在并且具有有效值。 会话 ID:34dd30479d6a440caf063493bd1abc3d
时间戳:2019-07-17T22:35:01.376Z
我想使用来自 Azure Function App 配置的值:
Azure 函数应用配置
非常感谢您阅读我的问题,祝您有美好的一天!
维托里奥
【问题讨论】:
标签: c# azure azure-functions azure-cosmosdb decorator