【发布时间】:2020-08-08 21:38:03
【问题描述】:
我正在尝试找出将存储帐户连接字符串传递给 CosmosDBTrigger 的正确方法。我有一个在 CosmosDB 容器发生更改时运行的函数。此函数将图像 blob 从一个容器复制到另一个容器。如果您查看下面的代码,我已经注释掉了我试图对要连接的存储帐户进行罚款的行。此函数在注释掉时运行。当我没有注释时它不会运行。为什么?
public static class Function1
{
[FunctionName("ImageCopier")]
public static async Task Run([CosmosDBTrigger(
databaseName: "MyDatabase",
collectionName: "Orders",
ConnectionStringSetting = "databaseConnection",
CreateLeaseCollectionIfNotExists = true,
LeaseDatabaseName = "TriggerLeases",
LeaseCollectionName = "TriggerLeases",
LeaseCollectionPrefix = "ImageCopier")]IReadOnlyList<Document> input,
//[StorageAccount("MyStorageAccount")]string storageConnectionString,
ILogger log)
{
我在我的 local.settings.json 文件中定义了 MyStorageAccount,并且在我的 Azure 函数配置设置中也有它。我直接从存储帐户密钥面板复制了连接字符串。
【问题讨论】:
-
几年前我问过这个问题:stackoverflow.com/questions/47625959/…
-
哦,我明白了,您需要一个存储帐户连接字符串。您可能必须将其存储在配置中并使用
Environment.GetEnvironmentVariable("storageConnectionString")在运行时拉取它。您可以将其存储在Values数组中的local.settings.json中以进行本地调试,然后在发布时将其放入Azure 中的配置中。 -
谢谢。这是有效的。
-
我会为这个问题添加一个答案,以便它可以帮助其他人
标签: azure azure-functions azure-cosmosdb