无法解析名为“存储”的Azure存储连接- Azure持久函数

mepcadol  于 2023-08-07  发布在  其他
关注(0)|答案(2)|浏览(121)

我的项目

package.json

  1. {
  2. "name": "azure-functions",
  3. "version": "1.0.0",
  4. "description": "",
  5. "scripts": {
  6. "start": "func start",
  7. "test": "echo \"No tests yet...\""
  8. },
  9. "dependencies": {
  10. "durable-functions": "^2.0.2"
  11. }
  12. }

字符串

host.json

  1. {
  2. "version": "2.0",
  3. "logging": {
  4. "applicationInsights": {
  5. "samplingSettings": {
  6. "isEnabled": true,
  7. "excludedTypes": "Request"
  8. }
  9. }
  10. },
  11. "extensionBundle": {
  12. "id": "Microsoft.Azure.Functions.ExtensionBundle",
  13. "version": "[3.*, 4.0.0)"
  14. }
  15. }

DurableFunctionsHttpStart/function.json

  1. {
  2. "bindings": [
  3. {
  4. "authLevel": "anonymous",
  5. "name": "req",
  6. "type": "httpTrigger",
  7. "direction": "in",
  8. "route": "orchestrators/{functionName}",
  9. "methods": [
  10. "post",
  11. "get"
  12. ]
  13. },
  14. {
  15. "name": "$return",
  16. "type": "http",
  17. "direction": "out"
  18. },
  19. {
  20. "name": "starter",
  21. "type": "orchestrationClient",
  22. "direction": "in"
  23. }
  24. ]
  25. }

DurableFunctionsHttpStart/index.js

  1. const df = require("durable-functions");
  2. module.exports = async function (context, req) {
  3. const client = df.getClient(context);
  4. const instanceId = await client.startNew(req.params.functionName, undefined, req.body);
  5. context.log(`Started orchestration with ID = '${instanceId}'.`);
  6. return client.createCheckStatusResponse(context.bindingData.req, instanceId);
  7. };

Hello/function.json

  1. {
  2. "bindings": [
  3. {
  4. "name": "name",
  5. "type": "activityTrigger",
  6. "direction": "in"
  7. }
  8. ]
  9. }

Hello/index.js

  1. /*
  2. * This function is not intended to be invoked directly. Instead it will be
  3. * triggered by an orchestrator function.
  4. *
  5. * Before running this sample, please:
  6. * - create a Durable orchestration function
  7. * - create a Durable HTTP starter function
  8. * - run 'npm install durable-functions' from the wwwroot folder of your
  9. * function app in Kudu
  10. */
  11. module.exports = async function (context) {
  12. return `Hello ${context.bindings.name}!`;
  13. };

HelloOrchestator/function.json

  1. {
  2. "bindings": [
  3. {
  4. "name": "context",
  5. "type": "orchestrationTrigger",
  6. "direction": "in"
  7. }
  8. ]
  9. }

HelloOrchestrator/index.js

  1. /*
  2. * This function is not intended to be invoked directly. Instead it will be
  3. * triggered by an HTTP starter function.
  4. *
  5. * Before running this sample, please:
  6. * - create a Durable activity function (default name is "Hello")
  7. * - create a Durable HTTP starter function
  8. * - run 'npm install durable-functions' from the wwwroot folder of your
  9. * function app in Kudu
  10. */
  11. const df = require("durable-functions");
  12. module.exports = df.orchestrator(function* (context) {
  13. const outputs = [];
  14. // Replace "Hello" with the name of your Durable Activity Function.
  15. outputs.push(yield context.df.callActivity("Hello", "Tokyo"));
  16. outputs.push(yield context.df.callActivity("Hello", "Seattle"));
  17. outputs.push(yield context.df.callActivity("Hello", "London"));
  18. // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
  19. return outputs;
  20. });


在页面的根目录上运行npm start时,我得到了以下错误。

  1. Azure Functions Core Tools
  2. Core Tools Version: 4.0.4736 Commit hash: N/A (64-bit)
  3. Function Runtime Version: 4.8.1.18957
  4. [2022-09-05T11:52:51.483Z] A host error has occurred during startup operation '5dd1dd91-e64a-4866-......'.
  5. [2022-09-05T11:52:51.483Z] Microsoft.Azure.WebJobs.Extensions.DurableTask: Unable to resolve the Azure Storage connection named 'Storage'.
  6. Value cannot be null. (Parameter 'provider')


原因可能是什么,我遵循了这个教程https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-js-vscode
我https://learn.microsoft.com/en-us/azure/azure-functions/durable/quickstart-js-vscode#test-the-function-locally

uemypmqf

uemypmqf1#

该异常表明运行时找不到AzureWebJobsStorage的值。您的项目中应该有一个local.settings.json文件,看起来应该如下所示:

  1. {
  2. "IsEncrypted": false,
  3. "Values": {
  4. "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=....",
  5. "FUNCTIONS_WORKER_RUNTIME": "node"
  6. }
  7. }

字符串
应将AzureWebJobsStorage的值设置为Azure函数运行时所需的存储连接字符串。
请参阅:Azure函数的应用程序设置参考

zbdgwd5y

zbdgwd5y2#

我在另一个场景中得到了完全相同的错误

  • 耐用功能
  • 隔离模式
  • .NET 7

在我的例子中,它与这里提到的任何事情都完全无关。我在local.settings.json中有一个嵌套的配置元素,如下所示:

  1. {
  2. "IsEncrypted": false,
  3. "Values": {
  4. "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  5. "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
  6. "setting1": {
  7. "key1": "value1"
  8. }
  9. }
  10. }

字符串
结果函数主机不喜欢这样,一旦我扁平化配置结构,错误就消失了。

  1. {
  2. "IsEncrypted": false,
  3. "Values": {
  4. "AzureWebJobsStorage": "UseDevelopmentStorage=true",
  5. "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
  6. "setting1:key1": "value1"
  7. }
  8. }

展开查看全部

相关问题